Class AttrsDirective
object --+
|
Directive --+
|
AttrsDirective
Implementation of the py:attrs template directive.
The value of the py:attrs attribute should be a dictionary or a sequence
of (name, value) tuples. The items in that dictionary or sequence are
added as attributes to the element:
>>> from genshi.template import MarkupTemplate
>>> tmpl = MarkupTemplate('''<ul xmlns:py="http://genshi.edgewall.org/">
... <li py:attrs="foo">Bar</li>
... </ul>''')
>>> print tmpl.generate(foo={'class': 'collapse'})
<ul>
<li class="collapse">Bar</li>
</ul>
>>> print tmpl.generate(foo=[('class', 'collapse')])
<ul>
<li class="collapse">Bar</li>
</ul>
If the value evaluates to None (or any other non-truth value), no
attributes are added:
>>> print tmpl.generate(foo=None)
<ul>
<li>Bar</li>
</ul>
|
__call__(self,
stream,
directives,
ctxt,
**vars)
Apply the directive to the given stream. |
|
|
Inherited from Directive :
__init__ ,
__repr__
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__ ,
__str__
|
Inherited from Directive :
attach
|
Inherited from Directive :
expr
Inherited from object :
__class__
|
__call__(self,
stream,
directives,
ctxt,
**vars)
(Call operator)
|
|
Apply the directive to the given stream.
- Parameters:
stream - the event stream
directives - a list of the remaining directives that should
process the stream
ctxt - the context data
vars - additional variables that should be made available when
Python code is executed
- Overrides:
Directive.__call__
- (inherited documentation)
|