Created
April 28, 2016 14:10
-
-
Save darmie/f8211107261a85ba34840138240206c1 to your computer and use it in GitHub Desktop.
Trying to create a DSL that converts to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render_tags= (fn)-> | |
setfenv fn, setmetatable({}, { | |
__index:(tag_name)=> | |
print tag_name | |
(opts)-> | |
build_tag(tag_name, opts) | |
}) | |
fn! | |
buid_tag= (tag_name, opts)-> | |
buffer = {'<', tag_name} | |
if type(opts) == "table" | |
for k,v in pairs(opts) | |
if type(k) != "number" | |
append_all buffer, " ", k, '="', v, '"' | |
if void_tags[tag_name] | |
append_all buffer, " />" | |
else | |
append_all buffer, ">" | |
if type(opts) == "table" | |
append_all buffer, unpack opts | |
else | |
append_all buffer, opts | |
append_all buffer, "</", tag_name, ">" | |
table.concat(buffer) | |
print buffer | |
append_all= (buffer,...)-> | |
for i=1,select("#", ...) | |
table.insert(buffer, (select(i, ...))) | |
class View | |
new:=> | |
render_tags(->@content!) | |
content: => { | |
layout { | |
type: "vertical" | |
text "hello" | |
} | |
} | |
view = View! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment