lua-users home
lua-l archive

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

Last year, I was inspired to write a Lua version of the Ruby XML Builder library:

I only made as much of it as I needed, and never published it until now:   -- the xml_builder.lua "lib"   -- the test program

    xm.html(                         -- <html>
        xm.head(                     --   <head>
            xm.title("History")      --     <title>History</title>
        ),                           --   </head>
        xm.body( { class = 'foo' },  --   <body class = "foo">
          xm.__comment "HI",         --     <!-- HI -->
          xm.h1("Header"),           --     <h1>Header</h1>
          xm.div{width="100%"},      --     <div width="100%"/>
          xm.p("paragraph")          --     <p>paragraph</p>
        )                            --   </body>
    )                                -- </html>
<html><head><title>History</title></head><body class="foo"><!-- HI --><h1>Header</h1><div width="100%"/><p>paragraph</p></body></html>

As with Petite Abeille's post, it's amazing how expressive of a DSL you can achieve with a few lines of Lua code.


On 5/12/11 8:28 AM, Emmanuel Oga wrote:
Hello, I was looking at this ruby library:

In which you can do things like:

HammerBuilder::Formated.get.go_in do
   html do
     head { title 'my_page' }
     body do
       div :id =>  'content' do
         p "my page's content", :class =>  'centered'
end.to_xhtml! # =>

I started to think this could be written more succinctly in lua:

local t = {
   html {
     head { title {'my_page'} },
     body { id='content',
       p { class='centered', "my page's content"}

It does not look that bad, does it? Here is some quick and dirty code
to render that template:

I'm wondering if there is already a lua project that handles a
template like in the example above.

I think writing a web application templates in the way outlined in
that example could be a viable option. What do you think?

-------------------------------------------------------------- - Software Developer