lua-users home
lua-l archive

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


Lua 5.2's _ENV functionality naturally expedites some fun syntax tricks;
partly for a side project, and partly for the fun of it, I wrote a
module that creates an _ENV object with a metatable to synthesize
HTML-wrapping functions. Thus,

local _ENV = require"htmlua".new()
return html {
    body {
        div {
            class = "class",
            p "Hello"
        }
    }
}

would yield "<html><body><div
class="class"><p>Hello</p></div></body></html>".


So then, for more fun, I had it generate callable tables instead of raw
functions. As tables, the HTML-wrappers can be further indexed to get
more-specific, class-tagged versions to fit a little more nicely with
today's CSS frameworks:

return html {
    body {
        div.class {
            p "Hello"
        },
        div.two.classes()
    }
}

yields "<html><body><div class=" class"><p>Hello</p></div><div class="
two classes"></div></body></html>"


Implementaion code at
http://fossil.tangent128.name/LuaForum/artifact/adbc426fafc3cb1f37e0a1a2d7f4f50cc4a498c0

~Joseph