Ñò
ûãtHc
@ sÕ d Z d d k Z d d k l Z d d k l Z l Z l Z l Z l Z l
Z
d d k l Z d d k
Td d k
l Z d d k l Z d d
d g Z d Z d e f d
„ ƒ YZ d
e f d „ ƒ YZ e Z d S( sß Plain text templating engine.
This module implements two template language syntaxes, at least for a certain
transitional period. `OldTextTemplate` (aliased to just `TextTemplate`) defines
a syntax that was inspired by Cheetah/Velocity. `NewTextTemplate` on the other
hand is inspired by the syntax of the Django template language, which has more
explicit delimiting of directives, and is more flexible with regards to
white space and line breaks.
In a future release, `OldTextTemplate` will be phased out in favor of
`NewTextTemplate`, as the names imply. Therefore the new syntax is strongly
recommended for new projects, and existing projects may want to migrate to the
new syntax to remain compatible with future Genshi releases.
iÿÿÿÿN( t TEXT( t BadDirectiveErrort Templatet TemplateSyntaxErrort EXECt INCLUDEt SUB( t Suite( t *( t Directive( t interpolatet NewTextTemplatet OldTextTemplatet TextTemplates restructuredtext enc
B s° e Z d Z d e f d e f d e f d e f d e f d e f d e f g Z
d Z d Z d
Z
d d d d d e d d „ Z d „ Z d „ Z e e e d ƒ Z d „ Z RS( s¾ Implementation of a simple text-based template engine. This class will
replace `OldTextTemplate` in a future release.
It uses a more explicit delimiting style for directives: instead of the old
style which required putting directives on separate lines that were prefixed
with a ``#`` sign, directives and commenbtsr are enclosed in delimiter pairs
(by default ``{% ... %}`` and ``{# ... #}``, respectively).
Variable substitution uses the same interpolation syntax as for markup
languages: simple references are prefixed with a dollar sign, more complex
expression enclosed in curly braces.
>>> tmpl = NewTextTemplate('''Dear $name,
...
... {# This is a comment #}
... We have the following items for you:
... {% for item in items %}
... * ${'Item %d' % item}
... {% end %}
... ''')
>>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render()
Dear Joe,