from jinja2.parser import Parser
from jinja2.optimizer import optimize
from jinja2.compiler import generate
-from jinja2.runtime import Undefined, Context, concat
+from jinja2.runtime import Undefined, Context
from jinja2.debug import translate_exception, translate_syntax_error
from jinja2.exceptions import TemplateSyntaxError
-from jinja2.utils import import_string, LRUCache, Markup, missing
+from jinja2.utils import import_string, LRUCache, Markup, missing, concat
# for direct template usage we have up to ten living environments
`variable_start_string`
The string marking the begin of a print statement.
Defaults to ``'{{'``.
-
+
`variable_stop_string`
The string marking the end of a print statement. Defaults to ``'}}'``.
`line_statement_prefix`
If given and a string, this will be used as prefix for line based
- statements.
+ statements. See also :ref:`line-statements`.
`trim_blocks`
If this is set to ``True`` the first newline after a block is
parent = dict(self.globals, **vars)
return Context(self.environment, parent, self.name, self.blocks)
+ def make_module(self, vars=None, shared=False):
+ """This method works like the :attr:`module` attribute when called
+ without arguments but it will evaluate the template every call
+ rather then caching the template. It's also possible to provide
+ a dict which is then used as context. The arguments are the same
+ as fo the :meth:`new_context` method.
+ """
+ return TemplateModule(self, self.new_context(vars, shared))
+
@property
def module(self):
"""The template as module. This is used for imports in the
"""
if hasattr(self, '_module'):
return self._module
- self._module = rv = TemplateModule(self, self.new_context())
+ self._module = rv = self.make_module()
return rv
def get_corresponding_lineno(self, lineno):
"""
def __init__(self, template, context):
- self.__body_stream = tuple(template.root_render_func(context))
+ # don't alter this attribute unless you change it in the
+ # compiler too. The Include without context passing directly
+ # uses the mangled name. The reason why we use a mangled one
+ # is to avoid name clashes with macros with those names.
+ self.__body_stream = list(template.root_render_func(context))
self.__dict__.update(context.get_exported())
self.__name__ = template.name