Package template3k
[hide private]
[frames] | no frames]

Package template3k

source code


This module provides support for simple but powerful templates. 
template3k is a template regular language based on substitution of
commands for their evaluation.

There exists two levels of execution:

Static level (substitution on template compilation time) or dynamic substitution
(executed on running time).

The entire template a python living code, so you can define python classes or
functions inside and use them at any time in the template.

It's based on commands that looks like simple html tags (to be easily used with
graphical html design applications).  The templates could not be an xml document,
but the commands will be named in the same way.

A template is executed with the method 'merge(values)' where values is a dictionary
with values to be used by the commands. Functions and lambdas in dynamic substitutions
receives as argument the merge's dictvalues as a dictionary

Commands:

python:keyword
   <python:keyword id="Name" />
       Replaces the command with values["Name"]
   <python:keyword id="Name">Default text</python:keyword>
       Replaces the command with values["Name"], with optionally default text

python:exec
   <python:exec id="Name">
   ...Python Code...
   </python:exec>
       Replaces the command with the result of compute the python code inside the command
       and whose varname is Name.
       If Name variable is a function or lambda it will be a dynamic substitution

python:code
   <python:code id="Name">
   ...Python Code...
   </python:code>
       Replaces the command with an empty string but the code is saved in the environment of
       the template, so its definitions could be used later

python:include
   <python:include id="Name">TemplatePath</python:include>
       Replaces the command with the template substituion of TemplatePath template. If must exists an special
       keyword |template_pool| in the merge dictionary to be used to get the template. If this key is not
       given in the merge, the default module get_template will be used. The arguments in the merge will be
       passed to this new template merge.
       
python:eval
   <python:eval id="Name">...Python Expression...</python:eval>
       Replaces the command with the result of the evaluation of the Python Expression inside the command tags.
       If Name is send to merge it will be replaced for the merge argument.
       If the result of the expression is a function or a lambda, it will be a dynamic substitution, a string
       otherwise. If Name is send to merge, the expression will not be executed. There is a implicit argument
       in the environment named dictvalues, is not needed in the Python Expression, but can be used in the
       Python Expression as well.

python:call
   <python:call id="Name">...Python Expression...</python:call>
       Replaces the command with the result of the evaluation of the Python Expression inside the command tags.
       If Name is send to merge it will be replaced for the merge argument.
       This expression will be always executed. If Name is send to merge, the expression will not be executed.



Classes [hide private]
  UnknownTemplateCommand
  Template
  Pool
Functions [hide private]
 
get_template(temname) source code
Variables [hide private]
  __doc__ = ...
  _pool = None
  _template_pattern = re.compile(r'(?imsx)<python:(?P<command>\w...
Variables Details [hide private]

__doc__

Value:
"""
This module provides support for simple but powerful templates. 
template3k is a template regular language based on substitution of
commands for their evaluation.

There exists two levels of execution:

Static level (substitution on template compilation time) or dynamic su\
...

_template_pattern

Value:
re.compile(r'(?imsx)<python:(?P<command>\w+)\s+id\s*=\s*["\'](?P<id>\w\
+)["\']\s*((/>)|(>(?P<defaultvalue>.*?)</python:(?P<endcommand>\w+)\s*\
>))')