| ryah ( @ 2008-05-11 18:17:00 |
| Entry tags: | io |
markaby-like html generation in io
i'm working on a little DSL for making HTML using Io. Here's what it looks like
html(
head(
title("ryan's web page")
)
body(
h1("ryan!")
br
form(action="/guestbook",
h2("sign my guest book!")
p(
label(for="name","name")
input(type="text",name="name")
)
p(
label(for="msg","msg")
input(type="text",name="msg")
)
input(type="submit",value="sign")
)
)
)Currently functional at 80 lines of code. For this I intercept each function call before it does anything, walk through it's argument list and see if it's a single = expression. These are stored as attributes. The last argument of the function is evaluated and added as children. Here is what it looks like TagCreator := block (
args := call message arguments
attr := Object clone
# Parse the arguments of the function into
# attributes and body.
innerHTML_msg := nil
args foreach(arg,
if( arg isSingular and arg name == "updateSlot"
, name := arg argAt(0) cachedResult
value := call sender doMessage(arg argAt(1))
attr setSlot(name, value)
, innerHTML_msg = arg
)
)
element := Element clone
element name := call message name
element parent := call sender
element attr := attr
if( element parent hasSlot("children")
, element parent children append(element)
)
if( innerHTML_msg
, r := doMessage(innerHTML_msg, element)
if(r type != "Element", element children append(r))
)
element
)Then for each tag-function i clone TagCreatorhtml := TagCreator clone setIsActivatable(true) head := TagCreator clone setIsActivatable(true) body := TagCreator clone setIsActivatable(true) ...I'll post the complete code once I get a chance to clean it up a bit.