[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Narcissus in Lua (Javascript parser)
- From: Javier Guerra Giraldez <javier@...>
- Date: Fri, 15 Oct 2010 15:53:36 -0500
On Fri, Oct 15, 2010 at 3:33 PM, Jonathan Castello <twisolar@gmail.com> wrote:
> On Fri, Oct 15, 2010 at 1:31 PM, Alex Queiroz <asandroq@gmail.com> wrote:
>> I thought that was a compliment. :)
>
> It certainly wasn't an insult. ;)
but the syntax is certainly ugly. this is what i actually use:
function string:template(variables)
return (self:gsub('{%%(.-)%%}', function (key) return
tostring(variables[key] or _G[key] or '') end))
end
use:
global_footer = 'copyright for myself, inc.'
print (([[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{%title%}</title>
</head>
<body>
<div id='header'><p>{%header%}</p></div>
<div id='main'>
<p>{%maintext%}</p>
<img src="{%picture_url%}" alt="{%picture_caption%}"/>
<a src="{%exit_url%}">{%exit_text%}</a>
</div>
<div id='footer'><p>{%global_footer%}</p></div>
</body>
</html>]]):template {
title='page title',
header= header div'',
maintext = 'main part',
picture_url = 'lolcats/purrr.jpg',
picture_caption = 'lol',
exit_url = 'somewhere/else.html',
exit_text = 'lets go',
})
--
Javier