Sneaky trick to edit and write out CSS from within the Translator

We’re doing a lot interesting projects with the Translator internally to the company. Many of these involve web technology and at the moment it’s a little inconvenient to edit HTML templates and CSS files in the Translator.

So I thought I would show this little trick to make it a bit easier, I wrote a little helper module called template that allowed me to do this type of thing:

require('template')

local Html=[[
<html>
<head>
<title>Script</title>
<link rel="stylesheet" type="text/css" href="hello.css">
</head>
<body>
<h1>It's a pleasure to update this.</h1>
<p>...and change the content on the fly.</p>
</body>
</html>
]]

local Css=[[
h1 {
color : blue
}
h1,p {
font-family : arial;
}
p{
color: green;
}
]]

function main(Data)
   template.Write('hello.html', Html)
   template.Write('hello.css', Css)
end

It actually writes the template files right into Iguana’s own web directory so you see the changes as they are made.  In this case the URL is something like:

http://<your iguana host>:6543/hello.html

template={}

function template.Write(Name, Content)
   if iguana.isTest() then
      local FileName = "web_docs/"..Name
      local F = io.open(FileName, "w")
      F:write(Content)
      F:close()
   end
end

The code works by detecting that we are in an edit mode and if and only them writing out the template files. Keep watching. You’ll see us add functionality to make web application development with the Translator easier over time.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.