git.s-ol.nu mmm / e677b8e
add _facet support to mmm.dom s-ol 4 months ago
2 changed file(s) with 30 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
77 else
88 attributes = {}
99
10 with e = document\createElement element
11 for k,v in pairs attributes
12 k = 'className' if k == 'class'
13 if k == 'style' and 'table' == type v
14 for kk,vv in pairs v
15 e.style[kk] = vv
16 elseif 'string' == type k
17 e[k] = v
10 e = if element then document\createElement element else document\createDocumentFragment!
1811
19 -- if there is only one argument,
20 -- children can be in attributes table too
21 if #children == 0
22 children = attributes
12 for k,v in pairs attributes
13 k = 'className' if k == 'class'
14 if k == 'style' and 'table' == type v
15 for kk,vv in pairs v
16 e.style[kk] = vv
17 elseif 'string' == type k
18 e[k] = v
2319
24 for child in *children
25 if 'string' == type child
26 child = document\createTextNode child
20 -- if there is only one argument,
21 -- children can be in attributes table too
22 if #children == 0
23 children, attributes = attributes, {}
2724
28 e\appendChild child
25 if not element
26 assert not (next attributes), "_frag cannot take attributes"
2927
30 setmetatable {}, __index: (name) =>
28 for child in *children
29 if 'string' == type child
30 child = document\createTextNode child
31
32 e\appendChild child
33
34 e
35
36 setmetatable { _frag: element! }, __index: (name) =>
3137 with val = element name
3238 @[name] = val
2424 -- if there is only one argument,
2525 -- children can be in attributes table too
2626 if #children == 0
27 children = attributes
27 children, attributes = attributes, {}
2828
2929 for i,v in ipairs children
3030 if 'string' != type v
3232 error "wrong type: #{type v}"
3333 children[i] = '' unless v
3434
35 if void_tags[element]
35 if not element
36 assert not (next attributes), "_frag cannot take attributes"
37 table.concat children
38 else if void_tags[element]
3639 assert #children == 0, "void tag #{element} cannot have children!"
3740 b .. ">"
3841 else
3942 b ..= ">" .. table.concat children, ''
40 b ..= "</#{element}>"
41 b
43 b .. "</#{element}>"
4244
43 setmetatable {}, __index: (name) =>
45 setmetatable { _frag: element! }, __index: (name) =>
4446 with val = element name
4547 @[name] = val