some documentation improvements, jinja escapes " and ' now, both into charpoints...
[jinja2.git] / jinja2 / environment.py
index fd4f89ca697d439bef33423fa58cb7b8fb52f493..35bbb15fe6daf1d68ad4c12bbab56bc47f16201e 100644 (file)
@@ -14,10 +14,10 @@ from jinja2.lexer import Lexer
 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
@@ -91,7 +91,7 @@ class Environment(object):
     `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 ``'}}'``.
 
@@ -103,7 +103,7 @@ class Environment(object):
 
     `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
@@ -529,6 +529,15 @@ class Template(object):
             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
@@ -543,7 +552,7 @@ class Template(object):
         """
         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):
@@ -583,7 +592,11 @@ class TemplateModule(object):
     """
 
     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