rbatis_codegen/codegen/syntax_tree_pysql/
to_html.rs

1use crate::codegen::syntax_tree_pysql::{NodeType, ToHtml};
2
3impl ToHtml for NodeType {
4    fn as_html(&self) -> String {
5        match self {
6            NodeType::NString(n) => n.as_html(),
7            NodeType::NIf(n) => n.as_html(),
8            NodeType::NTrim(n) => n.as_html(),
9            NodeType::NForEach(n) => n.as_html(),
10            NodeType::NChoose(n) => n.as_html(),
11            NodeType::NOtherwise(n) => n.as_html(),
12            NodeType::NWhen(n) => n.as_html(),
13            NodeType::NBind(n) => n.as_html(),
14            NodeType::NSet(n) => n.as_html(),
15            NodeType::NWhere(n) => n.as_html(),
16            NodeType::NContinue(n) => n.as_html(),
17            NodeType::NBreak(n) => n.as_html(),
18            NodeType::NSql(n) => n.as_html(),
19        }
20    }
21}
22
23impl ToHtml for Vec<NodeType> {
24    fn as_html(&self) -> String {
25        let mut htmls = String::new();
26        for x in self {
27            htmls.push_str(&x.as_html());
28        }
29        htmls
30    }
31}
32
33pub fn to_html_mapper(args: &Vec<NodeType>, is_select: bool, fn_name: &str) -> String {
34    let htmls = args.as_html();
35    if is_select {
36        format!(
37            "<mapper><select id=\"{}\">{}</select></mapper>",
38            fn_name, htmls
39        )
40    } else {
41        format!(
42            "<mapper><update id=\"{}\">{}</update></mapper>",
43            fn_name, htmls
44        )
45    }
46}