aboutsummaryrefslogtreecommitdiffstats
path: root/lib/html.server.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-10-18 14:16:10 +0000
committers-ol <s-ol@users.noreply.github.com>2018-10-18 14:16:10 +0000
commit8844d29223626240ff99a0cdaccf1ee5a36cb3f6 (patch)
tree1740fd0291959aa8d3d0b266158d7eaaa685224d /lib/html.server.moon
parentupdate dependencies (diff)
downloadmmm-8844d29223626240ff99a0cdaccf1ee5a36cb3f6.tar.gz
mmm-8844d29223626240ff99a0cdaccf1ee5a36cb3f6.zip
towards self-compiling
Diffstat (limited to 'lib/html.server.moon')
-rw-r--r--lib/html.server.moon37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/html.server.moon b/lib/html.server.moon
new file mode 100644
index 0000000..bbeaa9d
--- /dev/null
+++ b/lib/html.server.moon
@@ -0,0 +1,37 @@
+element = (element) -> (...) ->
+ children = { ... }
+
+ -- attributes are last arguments but mustn't be a ReactiveVar
+ attributes = children[#children]
+ if 'table' == (type attributes) and not attributes.node
+ table.remove children
+ else
+ attributes = {}
+
+ b = "<#{element}"
+ for k,v in pairs attributes
+ if 'table' == type v
+ tmp = ''
+ for kk, vv in pairs v
+ tmp ..= "#{kk}: #{vv}; "
+ v = tmp
+ b ..= " #{k}=\"#{v}\""
+
+ -- if there is only one argument,
+ -- children can be in attributes table too
+ if #children == 0
+ children = attributes
+
+ b ..= ">" .. table.concat children, ''
+ b ..= "</#{element}>"
+ b
+
+elements = {}
+add = (e) -> elements[e] = element e
+
+for e in *{'div', 'form', 'span', 'a', 'p', 'button', 'ul', 'ol', 'li', 'i', 'b', 'u', 'tt'} do add e
+for e in *{'article', 'section', 'header', 'footer', 'content', 'pre'} do add e
+for e in *{'br', 'hr', 'img', 'input', 'p', 'textarea'} do add e
+for i=1,8 do add "h" .. i
+
+elements