genshi :: template :: markup :: MarkupTemplate :: Class MarkupTemplate

Class MarkupTemplate

           object --+        
                    |        
base.DirectiveFactory --+    
                        |    
            base.Template --+
                            |
                           MarkupTemplate

Implementation of the template language for XML-based templates.

>>> tmpl = MarkupTemplate('''<ul xmlns:py="http://genshi.edgewall.org/">
...   <li py:for="item in items">${item}</li>
... </ul>''')
>>> print(tmpl.generate(items=[1, 2, 3]))
<ul>
  <li>1</li><li>2</li><li>3</li>
</ul>
Nested Classes

Inherited from base.DirectiveFactory: __metaclass__

Instance Methods
 
__init__(self, source, filepath=None, filename=None, loader=None, encoding=None, lookup='strict', allow_exec=True)
Initialize a template from either a string, a file-like object, or an already parsed markup stream.
 
add_directives(self, namespace, factory)
Register a custom DirectiveFactory for a given namespace.

Inherited from base.Template: __getstate__, __repr__, __setstate__, generate

Inherited from base.DirectiveFactory: get_directive, get_directive_index

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

Class Variables
  DIRECTIVE_NAMESPACE = 'http://genshi.edgewall.org/'
  XINCLUDE_NAMESPACE = 'http://www.w3.org/2001/XInclude'
  directives = [('def', <class 'genshi.template.directives.DefDi...
  serializer = 'xml'
hash(x)

Inherited from base.Template: EXEC, EXPR, INCLUDE, SUB

Properties

Inherited from base.Template: stream

Inherited from object: __class__

Method Details

__init__(self, source, filepath=None, filename=None, loader=None, encoding=None, lookup='strict', allow_exec=True)
(Constructor)

 
Initialize a template from either a string, a file-like object, or an already parsed markup stream.
Parameters:
  • source - a string, file-like object, or markup stream to read the template from
  • filepath - the absolute path to the template file
  • filename - the path to the template file relative to the search path
  • loader - the TemplateLoader to use for loading included templates
  • encoding - the encoding of the source
  • lookup - the variable lookup mechanism; either "strict" (the default), "lenient", or a custom lookup class
  • allow_exec - whether Python code blocks in templates should be allowed
Overrides: object.__init__
(inherited documentation)

add_directives(self, namespace, factory)

 
Register a custom DirectiveFactory for a given namespace.
Parameters:
  • namespace (basestring) - the namespace URI
  • factory (DirectiveFactory) - the directive factory to register

Since: version 0.6


Class Variable Details

directives

Value:
[('def', <class 'genshi.template.directives.DefDirective'>),
 ('match', <class 'genshi.template.directives.MatchDirective'>),
 ('when', <class 'genshi.template.directives.WhenDirective'>),
 ('otherwise',
  <class 'genshi.template.directives.OtherwiseDirective'>),
 ('for', <class 'genshi.template.directives.ForDirective'>),
 ('if', <class 'genshi.template.directives.IfDirective'>),
 ('choose', <class 'genshi.template.directives.ChooseDirective'>),
...