Skip to content
Myr

Fixed a macro scoping bug discovered by ckknight introduced in one of the earlier changes for the 2.1 release.

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 4735fbd · Browse files · 2 files+37 added−0 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+37 added−0 removed

  • tests:+35 added−0 removed
  • other:+2 added−0 removed

2 files+37 added−0 removed

modified:jinja2/compiler.py+2 added
621 unmodified lines
622623 def macro_body(self, node, frame, children=None):624 """Dump the function def of a macro or call block."""625 frame = self.function_scoping(node, frame, children)626 # macros are delayed, they never require output checks627 frame.require_output_check = False628 args = frame.arguments629 self.writeline('def macro(%s):' % ', '.join(args), node)630 self.indent()631 self.buffer(frame)
812 unmodified lines
modified:tests/test_inheritance.py+35 added
129 unmodified lines
130 tmpl = env.get_template('child')131 assert tmpl.render(master='master2') == 'MASTER2CHILD'132 assert tmpl.render(master='master1') == 'MASTER1CHILD'133 assert tmpl.render() == 'MASTER1CHILD'134135136def test_fixed_macro_scoping_bug():137 assert Environment(loader=DictLoader({138 'test.html': '''\139 {% extends 'details.html' %}140141 {% macro my_macro() %}142 my_macro143 {% endmacro %}144145 {% block inner_box %}146 {{ my_macro() }}147 {% endblock %}148 ''',149 'details.html': '''\150 {% extends 'standard.html' %}151152 {% macro my_macro() %}153 my_macro154 {% endmacro %}155156 {% block content %}157 {% block outer_box %}158 outer_box159 {% block inner_box %}160 inner_box161 {% endblock %}162 {% endblock %}163 {% endblock %}164 ''',165 'standard.html': '''166 {% block content %} {% endblock %}167 '''168 })).get_template("test.html").render().split() == [u'outer_box', u'my_macro']