diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-09-05 00:36:00 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-09-05 00:36:00 +0000 |
| commit | ece199a92220deaa3212fad30f6026693ae86c63 (patch) | |
| tree | f576a8c160c8827050ef34f474961d89bdff1ac4 /app/html.server.moon | |
| parent | some fixes (diff) | |
| download | mmm-ece199a92220deaa3212fad30f6026693ae86c63.tar.gz mmm-ece199a92220deaa3212fad30f6026693ae86c63.zip | |
polymorphic!
Diffstat (limited to 'app/html.server.moon')
| -rw-r--r-- | app/html.server.moon | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/html.server.moon b/app/html.server.moon new file mode 100644 index 0000000..6bd05e1 --- /dev/null +++ b/app/html.server.moon @@ -0,0 +1,36 @@ +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', '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 |
