lua-users home
lua-l archive

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


On Thu, May 12, 2011 at 3:52 PM, Petite Abeille
<petite.abeille@gmail.com> wrote:
>
> On May 12, 2011, at 8:40 PM, Romulo 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.
>
> Totally agree. While the DSL part of the exercise is somewhat interesting, the practicality of the result is dubious at best.
>
> I personally tend to use simple variable substitutions.
>
> E.g. the following page:
>
> http://svr225.stepx.com:3388/main
>
> Is defined as:
>
> http://dev.alt.textdrive.com/browser/HTTP/WikiLayout.txt
>
> And rendered by:
>
> http://dev.alt.textdrive.com/browser/HTTP/Template.lua#L156

yeah using keys like "_if" for logic does not look very good to me. I
would look better if you user helpers for logic:

instead of:

body{
  _if = 'user.logged_in', 'Welcome!',
  _if = 'not user.logged_in', 'Please login'
}

you could even return other templates in such helpers:

local t = require("tags")

local loggedinpartial = t.a { href="/blah", "Login" }
local notloggedinpartial = t.em { "Welcome!" }

funcion logblock()
  t.div { user.logged_in && loggedinpartial or notloggedinpartial }
end

return t.html {
   t.body{
    logdiv,
  }
 }

you get the idea, you get a kind of logic less template that way.


--------------------------------------------------------------
EmmanuelOga.com - Software Developer


>
>
>
>