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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use crate::codegen::html_loader::Element;
use crate::codegen::syntax_tree::NodeType;
use std::collections::HashMap;
pub fn as_elements(arg: Vec<NodeType>) -> Vec<Element> {
let mut res = vec![];
for x in arg {
res.push(Element::from(x));
}
res
}
impl From<NodeType> for Element {
fn from(arg: NodeType) -> Self {
match arg {
NodeType::NString(n) => {
return Element {
tag: "".to_string(),
data: n.value,
attrs: Default::default(),
childs: vec![],
};
}
NodeType::NIf(n) => {
let mut m = HashMap::new();
m.insert("test".to_string(), n.test);
return Element {
tag: "if".to_string(),
data: "".to_string(),
attrs: m,
childs: as_elements(n.childs),
};
}
NodeType::NTrim(n) => {
let mut m = HashMap::new();
m.insert("trim".to_string(), n.trim);
return Element {
tag: "trim".to_string(),
data: "".to_string(),
attrs: m,
childs: as_elements(n.childs),
};
}
NodeType::NForEach(n) => {
let mut m = HashMap::new();
m.insert("collection".to_string(), n.collection);
m.insert("index".to_string(), n.index);
m.insert("item".to_string(), n.item);
return Element {
tag: "foreach".to_string(),
data: "".to_string(),
attrs: m,
childs: as_elements(n.childs),
};
}
NodeType::NChoose(n) => {
let mut whens = as_elements(n.when_nodes);
if let Some(v) = n.otherwise_node {
whens.push(Element::from(*v));
}
return Element {
tag: "choose".to_string(),
data: "".to_string(),
attrs: Default::default(),
childs: whens,
};
}
NodeType::NOtherwise(n) => {
return Element {
tag: "otherwise".to_string(),
data: "".to_string(),
attrs: Default::default(),
childs: as_elements(n.childs),
};
}
NodeType::NWhen(n) => {
let mut m = HashMap::new();
m.insert("test".to_string(), n.test);
return Element {
tag: "when".to_string(),
data: "".to_string(),
attrs: m,
childs: as_elements(n.childs),
};
}
NodeType::NBind(n) => {
let mut m = HashMap::new();
m.insert("name".to_string(), n.name);
m.insert("value".to_string(), n.value);
return Element {
tag: "bind".to_string(),
data: "".to_string(),
attrs: m,
childs: vec![],
};
}
NodeType::NSet(n) => {
return Element {
tag: "set".to_string(),
data: "".to_string(),
attrs: Default::default(),
childs: as_elements(n.childs),
};
}
NodeType::NWhere(n) => {
return Element {
tag: "where".to_string(),
data: "".to_string(),
attrs: Default::default(),
childs: as_elements(n.childs),
};
}
NodeType::NContinue(n) => {
return Element {
tag: "continue".to_string(),
data: "".to_string(),
attrs: Default::default(),
childs: vec![],
};
}
}
}
}