-
Notifications
You must be signed in to change notification settings - Fork 1
/
htmlify.coffee
50 lines (40 loc) · 1.03 KB
/
htmlify.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Dependencies
_ = require 'lodash'
styleString = require './style-string.coffee'
# Utilities
{ deCamelCase } = require './utilities'
{ getElementById
createTextNode
createElement
querySelectorAll
querySelector } = require './doc'
module.exports = htmlify = (vo) ->
if vo.type is 'custom'
vo = vo.children[0]
_.reduce vo.children,
(el, child) =>
child = htmlify child
el.appendChild child
el
Single vo
module.exports.Text = Text =
(vo) -> createTextNode vo.content
module.exports.Single = Single = (vo) ->
return Text vo if vo.type is 'himesama-text'
_.reduce (_.keys vo.attributes),
(el, k) ->
v = vo.attributes[k]
k = deCamelCase k
switch k
when 'class-name'
el.setAttribute 'class', v
when 'style'
v = styleString v
el.setAttribute k, v
when 'event'
_.forEach (_.keys v), (e) =>
el.addEventListener e, v[e]
else
el.setAttribute k, v
el
createElement vo.type