Package genshi :: Package template :: Module directives :: Class StripDirective

Class StripDirective



object --+    
         |    
 Directive --+
             |
            StripDirective

Implementation of the py:strip template directive.

When the value of the py:strip attribute evaluates to True, the element is stripped from the output

>>> from genshi.template import MarkupTemplate
>>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
...   <div py:strip="True"><b>foo</b></div>
... </div>''')
>>> print tmpl.generate()
<div>
  <b>foo</b>
</div>

Leaving the attribute value empty is equivalent to a truth value.

This directive is particulary interesting for named template functions or match templates that do not generate a top-level element:

>>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
...   <div py:def="echo(what)" py:strip="">
...     <b>${what}</b>
...   </div>
...   ${echo('foo')}
... </div>''')
>>> print tmpl.generate()
<div>
    <b>foo</b>
</div>


Nested Classes

Inherited from Directive: __metaclass__

Instance Methods
 
__call__(self, stream, ctxt, directives)
Apply the directive to the given stream.

Inherited from Directive: __init__, __repr__

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Methods
 
attach(cls, template, stream, value, namespaces, pos)
Called after the template stream has been completely parsed.
Class Variables
  tagname = 'strip'
Properties

Inherited from Directive: expr

Inherited from object: __class__

Method Details

__call__(self, stream, ctxt, directives)
(Call operator)

 
Apply the directive to the given stream.
Overrides: Directive.__call__
(inherited documentation)

attach(cls, template, stream, value, namespaces, pos)
Class Method

 

Called after the template stream has been completely parsed.

This class method should return a (directive, stream) tuple. If directive is not None, it should be an instance of the Directive class, and gets added to the list of directives applied to the substream at runtime. stream is an event stream that replaces the original stream associated with the directive.

Overrides: Directive.attach
(inherited documentation)