7 | 7 |
else
|
8 | 8 |
attributes = {}
|
9 | 9 |
|
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!
|
18 | 11 |
|
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
|
23 | 19 |
|
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, {}
|
27 | 24 |
|
28 | |
e\appendChild child
|
|
25 |
if not element
|
|
26 |
assert not (next attributes), "_frag cannot take attributes"
|
29 | 27 |
|
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) =>
|
31 | 37 |
with val = element name
|
32 | 38 |
@[name] = val
|