aboutsummaryrefslogtreecommitdiffstats
path: root/app/html.client.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-09-05 00:36:00 +0000
committers-ol <s-ol@users.noreply.github.com>2018-09-05 00:36:00 +0000
commitece199a92220deaa3212fad30f6026693ae86c63 (patch)
treef576a8c160c8827050ef34f474961d89bdff1ac4 /app/html.client.moon
parentsome fixes (diff)
downloadmmm-ece199a92220deaa3212fad30f6026693ae86c63.tar.gz
mmm-ece199a92220deaa3212fad30f6026693ae86c63.zip
polymorphic!
Diffstat (limited to 'app/html.client.moon')
-rw-r--r--app/html.client.moon35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/html.client.moon b/app/html.client.moon
new file mode 100644
index 0000000..fdec714
--- /dev/null
+++ b/app/html.client.moon
@@ -0,0 +1,35 @@
+document = js.global.document
+
+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 = {}
+
+ with e = document\createElement element
+ for k,v in pairs attributes
+ e[k] = v
+
+ -- if there is only one argument,
+ -- children can be in attributes table too
+ if #children == 0
+ children = attributes
+
+ for child in *children
+ if 'string' == type child
+ e.innerHTML ..= child
+ else
+ e\appendChild child
+
+elements = {}
+add = (e) -> elements[e] = element e
+
+for e in *{'div', 'span', 'a', 'p', 'pre', 'button', 'ul', 'li', 'i', 'b', 'u', 'tt'} do add e
+for e in *{'br', 'img', 'input', 'p'} do add e
+for i=1,8 do add "h" .. i
+
+elements