Skip to content
Myr

Fixed a bug that caused syntax errors when defining macros or using the

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

`{% call %}` tag inside loops. This fixes #323. --HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent bec76c7 · Browse files · 4 files+23 added−3 removed
This commit

State

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

Diff stats

4 files+23 added−3 removed

  • tests:+15 added−0 removed
  • other:+8 added−3 removed

4 files+23 added−3 removed

modified:jinja2/compiler.py+4 added-1 removed
549 unmodified lines
550 for name in frame.identifiers.declared_locally:551 if name not in aliases:552 to_delete.add('l_' + name)553 if to_delete:554 self.writeline('del ' + ', '.join(to_delete))554 # we cannot use the del statement here because enclosed555 # scopes can trigger a SyntaxError:556 # a = 42; b = lambda: a; del a557 self.writeline(' = '.join(to_delete) + ' = missing')558559 def function_scoping(self, node, frame, children=None,560 find_special=True):561 """In Jinja a few statements require the help of anonymous
899 unmodified lines
modified:jinja2/debug.py+2 added-2 removed
9 unmodified lines
10 :copyright: (c) 2009 by the Jinja Team.11 :license: BSD.12"""13import sys14from jinja2.utils import CodeType14from jinja2.utils import CodeType, missing151617def translate_exception(exc_info):18 """If passed an exc_info it will automatically rewrite the exceptions
27 unmodified lines
46 locals = ctx.get_all()47 else:48 locals = {}49 for name, value in real_locals.iteritems():50 if name.startswith('l_'):50 if name.startswith('l_') and value is not missing:51 locals[name[2:]] = value5253 # if there is a local called __jinja_exception__, we get54 # rid of it to not break the debug functionality.
119 unmodified lines
modified:tests/test_forloop.py+15 added
158 unmodified lines
159 t = env.from_string('''160 {%- for item in foo recursive -%}{%- endfor -%}161 ''')162 assert t.render(dict(foo=[])) == ''163164165def test_call_in_loop(env):166 t = env.from_string('''167 {%- macro do_something() -%}168 [{{ caller() }}]169 {%- endmacro %}170171 {%- for i in [1, 2, 3] %}172 {%- call do_something() -%}173 {{ i }}174 {%- endcall %}175 {%- endfor -%}176 ''')177 assert t.render() == '[1][2][3]'
modified:CHANGES+2 added
8 unmodified lines
9 non existing templates.10- Priority of `not` raised. It's now possible to write `not foo in bar`11 as an alias to `foo not in bar` like in python. Previously the grammar12 required parentheses (`not (foo in bar)`) which was odd.13- Fixed a bug that caused syntax errors when defining macros or using the14 `{% call %}` tag inside loops.1516Version 2.1.117-------------18(Bugfix release)
84 unmodified lines