comparison markup/template.py @ 205:56f5e93edc48

Add doctest to verify that the `py:attrs` directive correctly handles a sequence of `(name, value)` tuples.
author cmlenz
date Sat, 26 Aug 2006 00:17:03 +0000
parents 4140bff0d7d2
children d122ff386411
comparison
equal deleted inserted replaced
204:516a6cae0aa8 205:56f5e93edc48
192 192
193 193
194 class AttrsDirective(Directive): 194 class AttrsDirective(Directive):
195 """Implementation of the `py:attrs` template directive. 195 """Implementation of the `py:attrs` template directive.
196 196
197 The value of the `py:attrs` attribute should be a dictionary. The keys and 197 The value of the `py:attrs` attribute should be a dictionary or a sequence
198 values of that dictionary will be added as attributes to the element: 198 of `(name, value)` tuples. The items in that dictionary or sequence are
199 added as attributes to the element:
199 200
200 >>> tmpl = Template('''<ul xmlns:py="http://markup.edgewall.org/"> 201 >>> tmpl = Template('''<ul xmlns:py="http://markup.edgewall.org/">
201 ... <li py:attrs="foo">Bar</li> 202 ... <li py:attrs="foo">Bar</li>
202 ... </ul>''') 203 ... </ul>''')
203 >>> print tmpl.generate(foo={'class': 'collapse'}) 204 >>> print tmpl.generate(foo={'class': 'collapse'})
205 <ul>
206 <li class="collapse">Bar</li>
207 </ul>
208 >>> print tmpl.generate(foo=[('class', 'collapse')])
204 <ul> 209 <ul>
205 <li class="collapse">Bar</li> 210 <li class="collapse">Bar</li>
206 </ul> 211 </ul>
207 212
208 If the value evaluates to `None` (or any other non-truth value), no 213 If the value evaluates to `None` (or any other non-truth value), no
Copyright (C) 2012-2017 Edgewall Software