lua-users home
lua-l archive

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


On Thu, May 12, 2011 at 16:05, Emmanuel Oga <emmanueloga@gmail.com> wrote:
> yeah using keys like "_if" for logic does not look very good to me. I
> would look better if you user helpers for logic:

Indeed. The usage of _if, _for etc. was inspired by CherryPy's own
syntax (py:if, py:for respectively). It looked so elegant on xhtml
files, but unfortunately not as good when embedded within a
Lua-DSL-compiled-to-Lua-source template.

The template file was compiled to a Lua sorce file, and the content of
such special attributes was used verbatim in the resulting script.

The template:

body{ p{ _for = 'i, item in ipairs( items )', _if = 'item.activated',
'${ item.text }' } }

Was compiled to:

 return function( out, sanitize, params )
  --setfenv( <this closure>, { __index = params } )

  out( '<body>' )
  for i, item in ipairs( items ) do
    if ( item.activated ) then
      out( '<p>', sanitize( item.text ), '</p>' )
    end
  end
  out('</body>')
 end


For this reason, compiling a template to a Lua source, the attrs _if,
_for, _strip etc. made sense.

Perhaps I should have used the same approach as CherryPy, parsing a
xhtml file to generate another xhtml file. Perhaps I should have used
yours and Orbit's approach to not compile the template as a Lua source
code and generate the HTML at the same time. However, I did both and I
do regret today.

--rb

ps: I am not saying mixing both worlds would not work. I am just
saying my version didn't work for me and my team at that time. YMMV.