how to loop in lua page(not the php way) ?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

how to loop in lua page(not the php way) ?

gary ng
Hi,

I am wondering if is possible to loop in lua page in a
more "declarative" way as in 

http://kid-templating.org/language.html

That is instead of :

<?lua
for i=1,10 do
  cgilua.put(string.format("<p>%s</p>"), tostring(i))
end
?>

but something like(completely made up syntax):

<p <?= loop(10) ?>> <?= item ?> </p>



 
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check. 
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html 

Reply | Threaded
Open this post in threaded view
|

Re: how to loop in lua page(not the php way) ?

Tomás Guisasola-2
	Hi Gary

> I am wondering if is possible to loop in lua page in a
> more "declarative" way as in 
> 
> http://kid-templating.org/language.html
	There is a study to use some concepts of StringTemplate
in Lua (I can find a reference to it if you want).  IMHO, it is
much better than the original one :-)

> That is instead of :
> 
> <?lua
> for i=1,10 do
>   cgilua.put(string.format("<p>%s</p>"), tostring(i))
> end
> ?>
> 
> but something like(completely made up syntax):
> 
> <p <?= loop(10) ?>> <?= item ?> </p>
	You could do something like:

<?lua
for i=1,10 do
?>
<p><%= tostring(i) %></p>
<?lua
end
?>

	Verbose isn't it?  With LuaST it would be in just one line!

	Regards,
		Tomás


Reply | Threaded
Open this post in threaded view
|

Re: how to loop in lua page(not the php way) ?

gary ng
--- Tomas Guisasola Gorham <[hidden email]>
wrote:
Hi Tomas,

> There is a study to use some concepts of
> StringTemplate in Lua (I can find a reference to it 
> if you want).  IMHO, it is much better than the 
> original one :-)
I am interested though something that is usable is
more important(as I am still learning) and the only
thing I can find about SringTemplate is "java/c#"
which sounds scary for me :-)

> 	You could do something like:
> 
> <?lua
> for i=1,10 do
> ?>
> <p><%= tostring(i) %></p>
> <?lua
> end
> ?>
> 
> 	Verbose isn't it?  With LuaST it would be in just
> one line!
That is what I am doing but still find it to be too
"procedural".

BTW, I notice the mentioning of Orbit for Kepler but
fail to find anything in the CVS. Is that only a todo
or is happening ?

The current kepler stock approach of one file for each
page is fine but a bit hard to maintain when it gets
complicated.

regards

gary


 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 

Reply | Threaded
Open this post in threaded view
|

Re: how to loop in lua page(not the php way) ?

Andre Carregal
On 15/03/2007, at 09:13, gary ng wrote:
BTW, I notice the mentioning of Orbit for Kepler but
fail to find anything in the CVS. Is that only a todo
or is happening ?

You can access a prototype of Orbit on its LuaForge page:
http://luaforge.net/scm/?group_id=171

Just keep in mind that we plan to rethink the current API so things can change in the future releases.

The current kepler stock approach of one file for each
page is fine but a bit hard to maintain when it gets complicated.

Right, that's why we are working on Orbit and the alternative template syntax mentioned by Tomás. By the way, the new template engine is similar to StringTemplate just on the motivation (simpler syntax, non turing complete), not on the details.

If you'd like to follow the discussions and help us get both products better, feel free to join the Kepler mailing list.

André




Reply | Threaded
Open this post in threaded view
|

Re: how to loop in lua page(not the php way) ?

Mark Edgar-2
In reply to this post by Tomás Guisasola-2
On 3/15/07, Tomas Guisasola Gorham <[hidden email]> wrote:
<?lua
for i=1,10 do
?>
<p><%= tostring(i) %></p>
<?lua
end
?>

I can't stand all the <?lua ?> cruft.  Instead, I use slslpp:
http://lua-users.org/wiki/SlightlyLessSimpleLuaPreprocessor

# for i = 1,10 do
<p>$(i)</p>
# end

Of course, this doesn't answer the OP's question.  I think the answer
to that question is: if you want KidLanguage, you know where to find
it. ;)

    -Mark

Reply | Threaded
Open this post in threaded view
|

Re: how to loop in lua page(not the php way) ?

Romulo Bahiense
Mark Edgar wrote:
On 3/15/07, Tomas Guisasola Gorham <[hidden email]> wrote:
<?lua
for i=1,10 do
?>
<p><%= tostring(i) %></p>
<?lua
end
?>

I can't stand all the <?lua ?> cruft.  Instead, I use slslpp:
http://lua-users.org/wiki/SlightlyLessSimpleLuaPreprocessor

# for i = 1,10 do
<p>$(i)</p>
# end

Of course, this doesn't answer the OP's question.  I think the answer
to that question is: if you want KidLanguage, you know where to find
it. ;)



Well... I actually have implemented my template library inspired on Kid.
I like Lua, like Kid but don't quite like XML, so...

-- sometemplate.lua
html{
  head{
    title{ "Hello, world" };
    link{ rel = "stylesheet", src = "style.css" };
  };
  body{
    div{ id = "header"; "Welcome to ${sitetitle}!" };
    div{ _if = "session.logged"; id = "menu"; class = "sidemenu";
      ul{
        li{ _for = "i, section in ipairs( session.sections )";
            a{ href = "${section.href}", "${section.title}" };
        };
      };
    };
  };
};

And it compiles (on the fly) another Lua script (for performance and debugging reasons):

out("<html>")
out("<head>")
out("<title>")
out("Hello, world")
...
out("<div id=\"header\">")
out("Welcome to ")
out(sanitize(sitetitle))
out("!")
if (session.logged) then
  out("<div id=\"menu\" class=\"sidemenu\">")
  out("<ul>")
  for i, section in ipairs( session.sections ) do
    out("<li>")
    out("<a href=\"")
    out(section.href)
    out("\">")
    out(sanitize(section.title))
    out("</a>")
    out("</li>")
  end
  out("</ul>")
  out("</div>")
end
...
out("</html>")


Of course, in real-world, I optimize those outputs to something like:

out("<html><head><title>Hello, World</title> ... <div id=\"header\">Welcome to ", sanitize(sitetile), "!")
if (session.logged) then
  out("<div id=\"menu\" class=\"sidemenu\"><ul>")
  for i, section in ipairs( session.sections ) do
out("<li><a href=\"",section.href,"\">",sanitize(section.title),"</a></li>")
  end
  out("</ul></div>")
end
out("...</body></html>")

I must say it is quite comfortable and fast. The only drawback is that debug can get a bit boring, because the line numbers differs (the one in which the expression was declared and the one which lies on the compiled code)

--rb

Reply | Threaded
Open this post in threaded view
|

Re: how to loop in lua page(not the php way) ?

Tomás Guisasola-2
	Hi Romulo

> Well... I actually have implemented my template library inspired on Kid.
> I like Lua, like Kid but don't quite like XML, so...
	Do you know HTK (http://www.tecgraf.puc-rio.br/~tomas/htk/)?
I think using both Lua Pages and HTK is great.  We're not using LuaST
in production code, so I cannot say anything about it with respect to 
debugging nor maintainability.

	Regards,
		Tomás