On Thu, May 12, 2011 at 15:05, Petite Abeille <
petite.abeille@gmail.com> wrote:
> On May 12, 2011, at 5:28 PM, Emmanuel Oga wrote:
>> I think writing a web application templates in the way outlined in
>> that example could be a viable option. What do you think?
>
> Well, I personally think it's a baroque waste of time :))
>From my experience, this approach is bad. Your designers won't like
it, your co-workers won't like it. Eventually you won't like it
either. It is easier to just inject Lua into a html file than to write
everything with Lua.
I've used a CherryPy-lke template engine with Orbit's idiom (eg: html{
body{ _if = 'user.logged_in', 'Welcome!' }, body{ _if = 'not
user.logged_in', 'Please login' } } ). However:
1. There was a lot confusion about how to use template's context. A
commom mistake was to try to access directly a context variable: "p{
user.name }" instead of "p{ '${ user.name }' }"
2. Templates got complex very quickly. Too many nested tags, too many
missed colons/curly braces. No syntax highlighting to aid finding
typos (a proper configured editor could've solved all that, but there
was none).
3. We had to either populate scripts' environment with functions like
html{}, body{}, span{}, ins{}, del{}, table_{}, or to live with with
undetected compile-time typos (i.e.: auto create functions on __index
hit)
4. The most important: every html file had to be translated to Lua's
syntax. Designers didn't quite like me.
Nowadays I use a Django-like template syntax and is working fine so far.
The usage got simpler also:
Template'<html><body>{% if logged_in %}Welcome{% else %}Please login{%
end %}</title><body>...</body>' { logged_in = ctx.session:is_logged()
}
or
Template'/my/proj/templates/simple_site.html'{ logged_in =
ctx.session:is_logged() }
--rb