name -- template file name or file-like object
from_string -- if True treat name as a string containing the
template data instead of a file to read from
auto_reload -- if the template has not been checked in this
many seconds then check it and reload if there
are any changes. If 'never' only load the
template file once.
Checking and reloading is done by the
start_file() function.
Ignored if from_string is True or if name is a
file-like object.
allow_degenerate -- If True then template is allowed to not
have a {contents}...{/contents} block. In this
case the entire file is available as a layer
called '*'. eg. l = tmpl.format('*', ...)
encoding -- encoding for template file
name -- template file name or file-like object
from_string -- if True treat name as a string containing the
template data instead of a file to read from
auto_reload -- if the template has not been checked in this
many seconds then check it and reload if there
are any changes. If 'never' only load the
template file once.
Checking and reloading is done by the
start_file() function.
Ignored if from_string is True or if name is a
file-like object.
allow_degenerate -- If True then template is allowed to not
have a {contents}...{/contents} block. In this
case the entire file is available as a layer
called '*'. eg. l = tmpl.format('*', ...)
encoding -- encoding for template file
template -- template object for generating this layer
header -- text before the content of this layer
footer -- text after the content of this layer
This constructor should not be called directly. Use
the open() function in a FileWriter or the open_layer()
function in another Layer object to create a new Layer.
django_form(form, errors=True, join_errors=<function <lambda> at 0x402695dc>)
Converts a django FormWrapper object to a dictionary that
can be used by Templayer. Each field is rendered into a
%form.NAME% slot.
If errors is True then this function will also render
errors into %form.NAME.errors% slots.
When there is more than one error on a single field the
errors will be joined with the join_errors function.
The default join_errors function puts a newline between each
error.
eg:
If tmpl is an HTMLTemplate object with a {form_layer} layer
and form is a FormWrapper object with username and password
fields, then this code will fill the {form_layer} layer's
%title%, %form.username%, %form.password%,
%form.username.errors% and %form.password.errors% slots:
This is a decorator for functions you want to make behave like
standard Django templates. When django_template_loader is
included in settings.TEMPLATE_LOADERS Django will find the
decorated function when looking for template_name.
tmpl is the Templayer template object that will be used to create
the file layer passed to the decorated function.
The decorated function must have a signature like:
@templayer.django_template(tmpl, "appname/somepage.html")
def mock_template(fwriter, context, optional1, optional2 ...)
Where fwriter is a new FileWriter object, context is a context
instance and all parameters that follow will have their values
copied from the context based on the name of the parameters.
The function must call fwriter.open(..) to render the page then
return the fwriter object (or None) to send it to the client.
fwriter.close() is called automatically. Other objects returned
or exceptions raised will be passed through to Django.
This is a decorator for Django view functions that will handle
creation of the file layer object from the template tmpl.
The function must have a signature like:
@templayer.django_view(tmpl)
def decorated_view(fwriter, request, ...)
fwriter is the new FileWriter object and the rest of the parameters
are the same as what was passed to the view.
The function must call fwriter.open(..) to render the page then
return the fwriter object (or None) to send it to the client.
fwriter.close() is called automatically. Other objects returned
or exceptions raised will be passed through to Django.
HTML markup is expanded recursively. Each of the content
values below are passed to expand_html_markup again before
applying the operation on the right:
string or unicode string -> HTML-escaped version of string
[content1, content2, ...] -> concatenate content1, content2, ...
('join',list,sep) -> join items in list with seperator sep
('pluralize',count,singular_content,plural_content)
-> if count == 1 use singular_content,
otherwise use plural_content
('urljoin',head,tail) -> join safe url head with unsafe url-ending tail
('href',link,content) -> HTML href to link wrapped around content
('target',name) -> HTML target name
('br',) -> HTML line break
('br',count) -> HTML line break * count
('p',) -> HTML paragraph break
('p',content) -> HTML paragraph
('i',content) -> italics
('b',content) -> bold
('u',content) -> underline
('&',entity) -> HTML entity (entity has no & or ;)
RawHTML(value) -> value unmodified