Repository navigation
Expand file tree
/
Copy pathtest_taglibs.py
More file actions
148 lines (137 loc) · 3.69 KB
/
Copy pathtest_taglibs.py
File metadata and controls
148 lines (137 loc) · 3.69 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#coding=utf8
from uliweb.core.taglibs import parse, Loader, parse_xml
tags = {'panel':
"""<div {%=to_attrs(_attrs, {'class':'panel'})%}>
<div class="panel-head">
<h3>{%<< xml(head)%}</h3>
{% if defined('button'):%}
{%<< xml_full('button', button)%}
{%pass%}
</div>
</div>""",
'button':
"""<button class="btn btn-{%=_attrs['class']%}">{%=_text%}</button>"""
}
loader = Loader(tags=tags, tags_dir='taglibs')
def test_1():
"""
>>> t = \"\"\"
... Text
... <t:panel a="b">
... <head>head</head>
... </t:panel>
... End\"\"\"
>>> print parse(t, loader)
<BLANKLINE>
Text
<div a="b" class=" panel">
<div class="panel-head">
<h3>head</h3>
<BLANKLINE>
</div>
</div>
End
"""
def test_2():
"""
>>> t = '<t:button class="primary">Submit</t:button>'
>>> print parse(t, loader)
<button class="btn btn-primary">Submit</button>
"""
def test_3():
"""
>>> t = \"\"\"
... Text
... <t:panel a="b">
... <head>head</head>
... <t:button class="primary">Submit</t:button>
... </t:panel>
... End\"\"\"
>>> print parse(t, loader) # doctest: +REPORT_UDIFF
<BLANKLINE>
Text
<div a="b" class=" panel">
<div class="panel-head">
<h3>head</h3>
<BLANKLINE>
<button class="btn btn-primary">Submit</button>
<BLANKLINE>
</div>
</div>
End
"""
def test_4():
"""
>>> t = '<t:bs.button>Submit</t:bs.button>'
>>> print parse_xml(t)
OrderedDict([(u'bs.button', {'_text': u'Submit', '_attrs': OrderedDict()})])
"""
def test_5():
"""
>>> t = '<t:bs.button>Submit</t:bs.button>'
>>> print parse(t, loader)
<button class="btn">Submit</button>
<BLANKLINE>
"""
# t = """<t:breadcrumb>
# <a href="#" title="Home"></a>
# <a href="#" title="Library"></a>
# <a active="active" title="Data"></a>
# </t:breadcrumb>"""
# t = """<t:form_input_field name="title" label="label" required="required">
# <input type="text" value="value" placeholder="placeholder" help="help">
# <![CDATA[
# <h3>CDATA</h3>
# ]]>
# </input>
# </t:form_input_field>
# """
# tags = {'breadcrumb':"""<ul class="breadcrumb">
# {%for i, li in enumerate(a):
# active = li['_attrs'].get('active')
# title = li['_attrs'].get('title')
# href = li['_attrs'].get('href')%}
# {%if active:%}
# <li class="{%=active%}">{%=title%}
# {%if i<len(a)-1:%} <span class="divider">/</span>{%pass%}
# </li>
# {%else:%}
# <li><a href="{%=href%}">{%=title%}</a>
# {%if i<len(a)-1:%} <span class="divider">/</span>{%pass%}
# </li>
# {%pass%}
# {%pass%}
# </ul>"""}
# import logging
# logging.basicConfig(level=logging.INFO)
# log = logging.getLogger()
#
# tags = {'form_input_field':"""
# {%name=_attrs['name']%}
#
# <div class="control-group" id="div_field_{%=name%}">
# {%if _attrs.get('label'):%}
# <label class="control-label" for="field_{%=name%}">{%=_attrs['label']%}
# {%if _attrs.get('required'):%}
# :<span class="field_required">*</span>
# {%pass%}
# </label>
# {%pass%}
# <div class="controls">
# {%
# type = input['_attrs'].pop('type', 'text')
# help = input['_attrs'].pop('help', '')
# %}
# <input id="field_{%=name%}"
# name="{%=name%}"
# type="{%=type%}"
# {%=to_attrs(input['_attrs'])%}></input>
# {%if help:%}
# <p class="help help-block">{%<< help%}</p>
# {%pass%}
# </div>
# </div>
# """}
# loader = Loader(tags)
# print parse_xml(t)
# print parse(t, loader, log=log)