comparison default/input/xmlui.html @ 47:7d5cca978eeb

input/xmlui: XMLUI generation first draft
author Goffi <goffi@goffi.org>
date Sun, 24 Sep 2017 16:48:15 +0200
parents
children dfef430a26ef
comparison
equal deleted inserted replaced
46:0520b7c9dcc0 47:7d5cca978eeb
1 {% import 'input/field.html' as field %}
2
3 {# generate methods #}
4
5 {% macro generate_container(cont) %}
6 {% if cont.type == 'vertical' %}
7 {{ vertical_container(cont) }}
8 {% elif cont.type == 'pairs' %}
9 {{ pairs_container(cont) }}
10 {% elif cont.type == 'label' %}
11 {{ label_container(cont) }}
12 {% endif %}
13 {% endmacro %}
14
15 {% macro generate_widget(wid, id=none) %}
16 {% if wid.type == 'text' %}
17 {{ text_widget(wid, id=id) }}
18 {% elif wid.type == 'label' %}
19 {{ label_widget(wid) }}
20 {% elif wid.type == 'string' %}
21 {{ string_widget(wid, id=id) }}
22 {% elif wid.type == 'textbox' %}
23 {{ textbox_widget(wid, id=id) }}
24 {% elif wid.type == 'list' %}
25 {{ list_widget(wid, id=id) }}
26 {% endif %}
27 {% endmacro %}
28
29 {% macro generate_children(cont) %}
30 {% for child in cont.children %}
31 {% if child.category == 'container' %}
32 {{ generate_container(child) }}
33 {% else %}
34 {{ generate_widget(child) }}
35 {% endif %}
36 {% endfor %}
37
38 {% endmacro %}
39
40 {% macro generate(xmlui) %}
41 {{ generate_container(xmlui.main_cont) }}
42 {% endmacro %}
43
44 {# containers #}
45
46 {% macro vertical_container(cont) %}
47 <div class="xmlui_cont xmlui_cont_vertical">
48 {{ generate_children(cont) }}
49 </div>
50 {% endmacro %}
51
52 {% macro pairs_container(cont) %}
53 {# TODO: proper impelmentation (do the same as vertical container for now #}
54 <div class="xmlui_cont xmlui_cont_vertical">
55 {{ generate_children(cont) }}
56 </div>
57 {% endmacro %}
58
59 {% macro label_container(cont) %}
60 <div class="xmlui_cont xmlui_cont_vertical">
61 {% for child in cont.children %}
62 {% if loop.index is odd %}
63 {# label #}
64 {% set id = 'widget'|next_gidx %}
65 {% if child.type == 'label' %}
66 {{ label_widget(child, for=id) }}
67 {% endif %}
68 {% else %}
69 {# widget #}
70 {% set id = 'widget'|cur_gidx %}
71 {{ generate_widget(child, id=id) }}
72 {% endif %}
73 {% endfor %}
74 </div>
75 {% endmacro %}
76
77
78 {# widgets #}
79
80 {% macro text_widget(wid, id=none) %}
81 <p class="xmlui_widget xmlui_text" {{ {'id':id}|xmlattr }}>
82 {{wid.value}}
83 </p>
84 {% endmacro%}
85
86 {% macro label_widget(wid, for=none) %}
87 <label class="xmlui_widget xmlui_label"{{ {'for':for}|xmlattr }}>
88 {{wid.value}}
89 </label>
90 {% endmacro%}
91
92 {% macro string_widget(wid, id=none) %}
93 <input class="xmlui_widget xmlui_string" type="text" {{ {'name':wid.name, 'id':id, 'value':wid.value}|xmlattr }}>
94 {% endmacro%}
95
96 {% macro textbox_widget(wid, id=none) %}
97 <textarea class="xmlui_widget xmlui_textbox" rows="10" cols="50" {{ {'name':wid.name, 'id':id}|xmlattr }}>
98 {{- wid.value -}}
99 </textarea>
100 {% endmacro%}
101
102 {% macro list_widget(wid, id=none) %}
103 <select class="xmlui_widget xmlui_list"{{ {'name':wid.name, 'id':id}|xmlattr }}>
104 {% for value,label in wid.options %}
105 <option {{ {'value':value}|xmlattr }} {{ 'selected' if value == wid.selected }}>{{label}}</option>
106 {% endfor %}
107 </select>
108 {% endmacro%}