Skip to content

Commit

Permalink
fixed a problem with having call blocks in outer scopes that
Browse files Browse the repository at this point in the history
have an argument that is also used as local variable in an
inner frame [#360].

--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed Jan 14, 2010
1 parent a586989 commit e0016f5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Version 2.3
- include tags are now able to select between multiple templates - include tags are now able to select between multiple templates
and take the first that exists, if a list of templates is and take the first that exists, if a list of templates is
given. given.
- fixed a problem with having call blocks in outer scopes that
have an argument that is also used as local variable in an
inner frame [#360].


Version 2.2.1 Version 2.2.1
------------- -------------
Expand Down
2 changes: 1 addition & 1 deletion jinja2/compiler.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def visit_For(self, node):
self.visit(node.iter) self.visit(node.iter)


def visit_CallBlock(self, node): def visit_CallBlock(self, node):
for child in node.iter_child_nodes(exclude=('body',)): for child in node.iter_child_nodes(exclude=('body', 'args')):
self.visit(child) self.visit(child)


def visit_FilterBlock(self, node): def visit_FilterBlock(self, node):
Expand Down
35 changes: 34 additions & 1 deletion tests/test_old_bugs.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:copyright: (c) 2009 by the Jinja Team. :copyright: (c) 2009 by the Jinja Team.
:license: BSD. :license: BSD.
""" """
from jinja2 import Environment, DictLoader, TemplateSyntaxError from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError


env = Environment() env = Environment()


Expand Down Expand Up @@ -101,3 +101,36 @@ def test_stacked_locals_scoping_bug():
# endif # endif
''') ''')
assert t.render(a=0, b=False, c=42, d=42.0) == '1111C' assert t.render(a=0, b=False, c=42, d=42.0) == '1111C'


def test_call_with_args():
t = Template("""{% macro dump_users(users) -%}
<ul>
{%- for user in users -%}
<li><p>{{ user.username|e }}</p>{{ caller(user) }}</li>
{%- endfor -%}
</ul>
{%- endmacro -%}
{% call(user) dump_users(list_of_user) -%}
<dl>
<dl>Realname</dl>
<dd>{{ user.realname|e }}</dd>
<dl>Description</dl>
<dd>{{ user.description }}</dd>
</dl>
{% endcall %}""")

assert [x.strip() for x in t.render(list_of_user=[{
'username':'apo',
'realname':'something else',
'description':'test'
}]).splitlines()] == [
u'<ul><li><p>apo</p><dl>',
u'<dl>Realname</dl>',
u'<dd>something else</dd>',
u'<dl>Description</dl>',
u'<dd>test</dd>',
u'</dl>',
u'</li></ul>'
]

0 comments on commit e0016f5

Please sign in to comment.