sort now also accepts an attribute
[jinja2.git] / jinja2 / meta.py
index 3c7a0d391cfa850ee138e62a3d5ad823af724a6b..3a779a5e9a81a6b59b0fa1685c63e62e38a70b9c 100644 (file)
@@ -6,7 +6,7 @@
     This module implements various functions that exposes information about
     templates that might be interesting for various kinds of applications.
 
-    :copyright: (c) 2009 by the Jinja2 Team, see AUTHORS for more details.
+    :copyright: (c) 2010 by the Jinja Team, see AUTHORS for more details.
     :license: BSD, see LICENSE for more details.
 """
 from jinja2 import nodes
@@ -70,8 +70,33 @@ def find_referenced_templates(ast):
     """
     for node in ast.find_all((nodes.Extends, nodes.FromImport, nodes.Import,
                               nodes.Include)):
-        if isinstance(node.template, nodes.Const) and \
-           isinstance(node.template.value, basestring):
+        if not isinstance(node.template, nodes.Const):
+            # a tuple with some non consts in there
+            if isinstance(node.template, (nodes.Tuple, nodes.List)):
+                for template_name in node.template.items:
+                    # something const, only yield the strings and ignore
+                    # non-string consts that really just make no sense
+                    if isinstance(template_name, nodes.Const):
+                        if isinstance(template_name.value, basestring):
+                            yield template_name.value
+                    # something dynamic in there
+                    else:
+                        yield None
+            # something dynamic we don't know about here
+            else:
+                yield None
+            continue
+        # constant is a basestring, direct template name
+        if isinstance(node.template.value, basestring):
             yield node.template.value
+        # a tuple or list (latter *should* not happen) made of consts,
+        # yield the consts that are strings.  We could warn here for
+        # non string values
+        elif isinstance(node, nodes.Include) and \
+             isinstance(node.template.value, (tuple, list)):
+            for template_name in node.template.value:
+                if isinstance(template_name, basestring):
+                    yield template_name
+        # something else we don't care about, we could warn here
         else:
             yield None