aboutsummaryrefslogtreecommitdiffstats
path: root/app/html.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-05-04 23:06:20 +0000
committers-ol <s-ol@users.noreply.github.com>2018-05-04 23:06:20 +0000
commita26bd7d17cb0782da0c57bb10f6f3ffa4a0f070f (patch)
tree441ced6e7734c618cd078cf63a818a1eb6567f58 /app/html.moon
parentadd component framework + todo (diff)
downloadmmm-a26bd7d17cb0782da0c57bb10f6f3ffa4a0f070f.tar.gz
mmm-a26bd7d17cb0782da0c57bb10f6f3ffa4a0f070f.zip
add test suite
Diffstat (limited to 'app/html.moon')
-rw-r--r--app/html.moon26
1 files changed, 19 insertions, 7 deletions
diff --git a/app/html.moon b/app/html.moon
index 3565f32..fdec714 100644
--- a/app/html.moon
+++ b/app/html.moon
@@ -1,13 +1,25 @@
document = js.global.document
-element = (element) -> (attrs = {}, ...) ->
- if 'table' != type attrs
- attrs = { attrs, ... }
+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 attrs
- continue unless 'string' == type k
+ for k,v in pairs attributes
e[k] = v
- for child in *attrs
+
+ -- 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
@@ -16,7 +28,7 @@ element = (element) -> (attrs = {}, ...) ->
elements = {}
add = (e) -> elements[e] = element e
-for e in *{'div', 'span', 'a', 'p', 'button', 'ul', 'li', 'i', 'b', 'u', 'tt'} do add 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