From f9f029cd948438418599de600152ec3a4dab3af3 Mon Sep 17 00:00:00 2001 From: Christoph Hack Date: Wed, 9 Apr 2008 15:08:11 +0200 Subject: [PATCH] render templates --HG-- branch : trunk --- jinja2/runtime.py | 4 ++-- test.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 0e42005..cc5cfe1 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -149,7 +149,7 @@ class StaticLoopContext(LoopContextBase): class Macro(object): """ - Wraps a macor + Wraps a macro """ def __init__(self, func, name, arguments, defaults, catch_all): @@ -176,7 +176,7 @@ class Macro(object): value = self.defaults[idx - arg_count] except IndexError: value = Undefined(name) - arguments['l_' + name] = arg + arguments['l_' + name] = value if self.catch_all: arguments['l_arguments'] = kwargs return u''.join(self.func(**arguments)) diff --git a/test.py b/test.py index 67f19b6..7ab5b96 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,4 @@ +import sys from jinja2 import Environment from jinja2.compiler import generate @@ -9,9 +10,19 @@ ast = env.parse(""" {% macro foo(a) %}[{{ a }}|{{ b }}|{{ c }}]{% endmacro %} {% for item in seq %} {{ foo(item) }} - {% endfor %} + {%- endfor %} {% endblock %} """) print ast print -print generate(ast, env, "foo.html") +source = generate(ast, env, "foo.html") +print source +print + +# execute the template +code = compile(source, 'jinja://foo.html', 'exec') +context = {'seq': range(5), 'c': 'foobar'} +namespace = {'global_context': context} +exec code in namespace +for event in namespace['root'](context): + sys.stdout.write(event) -- 2.26.2