lua-users home
lua-l archive

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


it's part of a lua enable webserver that is still in a proof of concept
stage. It's called parcle, the template engine parclate.

Parclate basically parses xml into a DOM table representation and
serializes that into a function that concatenates a table for good
performance when that gets serialized. So there are two pathes a
template can take:
 - inline compilation
 - write to a file that can be require()

the two interesting functions for the setfenv issue are to_file and

Use example:
Parclate = require('lib.Parclate')
ts1 =[[<span l:for="k in numbers()" l:strip="">
    I am the <i>${k}</i> <b>${varname} line</b></br />

a1 = Parclate(ts1) -- generate tmpl representation from xml string
print (a1:debug()) -- runs to_file()
a = a1:compile()   -- can be shortcut as a=a1()
-- create the context for the template
a.varname = 'whatever'
a.numbers = function ()
   local i=0
   local t={'first','second','third','fourth','fifth','sixth'}
   return function()
      i = i + 1
      if t[i] then return t[i] end

-- runs __tostring on a
print (a) 

at the moment there is only variable substitution, if, for and strip

	- T

On Fri, 15 Jan 2010, Romulo wrote:
> Sorry for becoming OT, but I'd like to see an example of your
> implementation. Whilst I've done one myself, it'd be great to see what
> other people did that could add up.
> --rb