lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Jan 20, 2009, at 6:33 PM, Tobias Markmann wrote:

If not luarocks then it must be cosmo. I wonder if someone knows a different
template engine which is pure lua.

If you like it, hmmm, rather minimalist, Nanoki does have a rather straightforward template mechanism:

http://dev.alt.textdrive.com/browser/HTTP/Template.lua


Here is an usage example from Nanoki to displays the page index:

http://dev.alt.textdrive.com/browser/HTTP/WikiIndexService.txt

<h1>[v:title]</h1>
<h4>[v:description]</h4>
[v:navigation]
<br />
<ul>
[t:names]
    <li><a href='[v:href]' title='[v:name]'>[v:name]</a>[v:tag]</li>
[/t:names]
</ul>

Note the [v:variable] place holders for, well, variable substitutions and the [t:template][/t:template] for sub-templates. There are no other constructs.


Here is part of the code populating the template above:

http://dev.alt.textdrive.com/browser/HTTP/WikiIndexService.lua
local aTemplate = Template[ 'WikiIndexService.txt' ]
for aContent, aURL in anIterator do
    local aNameTemplate = aTemplate[ 'names' ]

    aNameTemplate[ 'href' ] = Encode( aURL.path )
    aNameTemplate[ 'name' ] = Encode( aContent.title )

    aTemplate[ 'names' ] = aNameTemplate
end

And here is the end result:

http://svr225.stepx.com:3388/index/a


Et voilà.

Cheers,

--
PA.
http://alt.textdrive.com/nanoki/