[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:11:48 -0500
On Fri, Oct 15, 2010 at 2:51 PM, kevin beckford <chiggsy@lazyweb.ca> wrote:
> Does a similar thing exist in Lua
untested:
function H (tag, attrs, c, ...)
o = {('<%s '):format(tag)}
if attrs then
for k,v in pairs(attrs) do
table.insert (o, ('%s="%s" '):format(k,v))
end
end
if c then
table.insert (o,'>')
table.insert (o, table.concat({c,...}))
table.insert (o, ('</%s>'):format(tag))
else
table.insert (o, '/>')
end
return table.concat(o)
end
use:
H('html',nil,
H('head',nil, H('title',nil, 'page title')),
H('body',nil,
H('div', {id='header',class='banner'},
H('p',nil, 'header div'))
H('div', {id='main'},
H('p',nil, 'main part'),
H('img', {src='lolcats/purrr.jpg', alt='lol'}),
H('a' {href='somewhere/else.html'}, 'lets go')),
H('div',{id='footer'}, H('p',nil,'the end'))))
--
Javier