-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_go_dom.cr
60 lines (46 loc) · 1.1 KB
/
first_go_dom.cr
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
50
51
52
53
54
55
56
57
58
59
60
module DOM
extend self
module NodeType
struct Text
property string
def initialize(@string : String)
end
def string : String
@string
end
end
struct Element
property tag_name, attributes
def initialize(@tag_name : String, @attributes : Hash(String, String))
end
def attributes : Hash(String, String)
@attributes
end
def tag_name : String
@tag_name
end
end
end
class Node
@children : Array(Node)
@node_type : NodeType::Element
def initialize(children, node_type)
@children = children
@node_type = node_type
puts typeof(node_type)
end
def children
@children
end
def node_type
@node_type
end
end
def text(data : String) : Node
Node.new children: [] of Node, node_type: NodeType::Text.new(data)
end
def element(name : String, attrs : Hash(String, String), children : Array(Node)) : Node
element_node = NodeType::Element.new tag_name: name, attributes: attrs
Node.new children: children, node_type: element_node
end
end