From e5491bc7fbd867812500c845db99b55b35db0666 Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 29 Oct 2018 19:37:40 +1100 Subject: rename lib.html to lib.dom --- lib/dom.server.moon | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/dom.server.moon (limited to 'lib/dom.server.moon') diff --git a/lib/dom.server.moon b/lib/dom.server.moon new file mode 100644 index 0000000..3a7b537 --- /dev/null +++ b/lib/dom.server.moon @@ -0,0 +1,33 @@ +import opairs from require 'lib.ordered' + +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 opairs attributes + if k == 'style' and 'table' == type v + tmp = '' + for kk, vv in opairs 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 ..= "" + b + +setmetatable {}, __index: (name) => + with val = element name + @[name] = val -- cgit v1.2.3