self.writeline('l_%s = context[%r]' % (name, name))
for name, count in frame.identifiers.undeclared_filter.iteritems():
if count > 1:
- self.writeline('f_%s = context[%r]' % (name, name))
+ self.writeline('f_%s = environment.filters[%r]' % (name, name))
if not no_indent:
self.outdent()
if node.name in frame.identifiers.declared_filter:
self.write('f_%s(' % node.name)
else:
- self.write('context.filter[%r](' % node.name)
+ self.write('environment.filters[%r](' % node.name)
self.visit(node.node, frame)
self.signature(node, frame)
self.write(')')
def visit_Test(self, node, frame):
- self.write('context.tests[%r](')
+ self.write('environment.tests[%r](')
self.visit(node.node, frame)
self.signature(node, frame)
self.write(')')
if isinstance(source, basestring):
source = self.parse(source, filename)
node = optimize(source, self)
- source = generate(node, self)
+ source = generate(node, self, filename)
if raw:
return source
+ print source
if isinstance(filename, unicode):
filename = filename.encode('utf-8')
return compile(source, filename, 'exec')
name = self.join_path(name, parent)
return self.loader.load(self, name)
+ def from_string(self, source, filename='<string>'):
+ """Load a template from a string."""
+ return Template(self, self.compile(source, filename))
+
class Template(object):
"""Represents a template."""
class BaseLoader(object):
+ """Baseclass for all loaders."""
def get_source(self, environment, template):
raise TemplateNotFound()
--- /dev/null
+from jinja2 import Environment
+
+env = Environment()
+tmpl = env.from_string("""
+<ul>
+{% for item in seq %}
+ <li>{{ item|e }}</li>
+{% endfor %}
+</ul>
+""")
+
+print tmpl.render(seq=range(10))