From: Christoph Hack Date: Wed, 9 Apr 2008 13:08:11 +0000 (+0200) Subject: render templates X-Git-Tag: 2.0rc1~196^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f9f029cd948438418599de600152ec3a4dab3af3;p=jinja2.git render templates --HG-- branch : trunk --- 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)