From: Armin Ronacher Date: Sun, 26 Jul 2009 08:33:36 +0000 (+0200) Subject: Added the `meta` module. X-Git-Tag: 2.2~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=63cf9b895df233a13af5d166d8639cb20583af65;p=jinja2.git Added the `meta` module. --HG-- branch : trunk --- diff --git a/CHANGES b/CHANGES index b218e87..b8450fc 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ Version 2.2 *before* the loop. (#331) - Added support for optional `scoped` modifier to blocks. - Added support for line-comments. +- Added the `meta` module. Version 2.1.1 ------------- diff --git a/docs/api.rst b/docs/api.rst index 5383293..5a1e29a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -665,3 +665,17 @@ don't recommend using any of those. change it in a backwards incompatible way but modifications in the Jinja2 core may shine through. For example if Jinja2 introduces a new AST node in later versions that may be returned by :meth:`~Environment.parse`. + +The Meta API +------------ + +.. versionadded:: 2.2 + +The meta API returns some information about abstract syntax trees that +could help applications to implement more advanced template concepts. All +the functions of the meta API operate on an abstract syntax tree as +returned by the :meth:`Environment.parse` method. + +.. autofunction:: jinja2.meta.find_undeclared_variables + +.. autofunction:: jinja2.meta.find_referenced_templates diff --git a/docs/conf.py b/docs/conf.py index 3bd30e1..ba90c49 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -95,9 +95,6 @@ html_last_updated_fmt = '%b %d, %Y' # typographically correct entities. #html_use_smartypants = True -# use jinja2 for templates -template_bridge = 'jinjaext.Jinja2Bridge' - # no modindex html_use_modindex = False diff --git a/docs/jinjaext.py b/docs/jinjaext.py index 212c8bf..66f4ba1 100644 --- a/docs/jinjaext.py +++ b/docs/jinjaext.py @@ -77,16 +77,6 @@ class JinjaStyle(Style): } -class Jinja2Bridge(TemplateBridge): - - def init(self, builder): - path = builder.config.templates_path - self.env = Environment(loader=FileSystemLoader(path)) - - def render(self, template, context): - return self.env.get_template(template).render(context) - - _sig_re = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*(\(.*?\))') diff --git a/jinja2/nodes.py b/jinja2/nodes.py index c7858b6..7c6c230 100644 --- a/jinja2/nodes.py +++ b/jinja2/nodes.py @@ -146,7 +146,9 @@ class Node(object): return result def find_all(self, node_type): - """Find all the nodes of a given type.""" + """Find all the nodes of a given type. If the type is a tuple, + the check is performed for any of the tuple items. + """ for child in self.iter_child_nodes(): if isinstance(child, node_type): yield child