Skip to content
Myr

render templates

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Christoph Hack · committed by Christoph Hack · parent 96beb07 · Browse files · 2 files+15 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−4 removed

  • other:+15 added−4 removed

2 files+15 added−4 removed

modified:jinja2/runtime.py+2 added-2 removed
147 unmodified lines
148149150class Macro(object):151 """152 Wraps a macor152 Wraps a macro153 """154155 def __init__(self, func, name, arguments, defaults, catch_all):156 self.func = func
18 unmodified lines
175 try:176 value = self.defaults[idx - arg_count]177 except IndexError:178 value = Undefined(name)179 arguments['l_' + name] = arg179 arguments['l_' + name] = value180 if self.catch_all:181 arguments['l_arguments'] = kwargs182 return u''.join(self.func(**arguments))183
31 unmodified lines
modified:test.py+13 added-2 removed
1import sys 2from jinja2 import Environment3from jinja2.compiler import generate45
3 unmodified lines
9 {% b = 23 %}10 {% macro foo(a) %}[{{ a }}|{{ b }}|{{ c }}]{% endmacro %}11 {% for item in seq %}12 {{ foo(item) }}12 {% endfor %}13 {%- endfor %}14{% endblock %}15""")16print ast17print17print generate(ast, env, "foo.html")18source = generate(ast, env, "foo.html")19print source20print2122# execute the template23code = compile(source, 'jinja://foo.html', 'exec')24context = {'seq': range(5), 'c': 'foobar'}25namespace = {'global_context': context}26exec code in namespace27for event in namespace['root'](context):28 sys.stdout.write(event)