Permalink
Browse files

Fixed imports with scoped blocks

  • Loading branch information...
1 parent 9573b66 commit 5f3d6618748a5402236c1c4cfc06238a6e23a15d @mitsuhiko mitsuhiko committed Dec 22, 2010
Showing with 26 additions and 0 deletions.
  1. +2 −0 CHANGES
  2. +1 −0 jinja2/runtime.py
  3. +23 −0 jinja2/testsuite/inheritance.py
View
@@ -15,6 +15,8 @@ Version 2.6
integers instead of longs)
- groupby filter now supports dotted notation for grouping by attributes
of attributes.
+- scoped blocks not properly treat toplevel assignments and imports.
+ Previously an import suddenly "disappeared" in a scoped block.
Version 2.5.5
-------------
View
@@ -190,6 +190,7 @@ def derived(self, locals=None):
"""Internal helper function to create a derived context."""
context = new_context(self.environment, self.name, {},
self.parent, True, None, locals)
+ context.vars.update(self.vars)
context.eval_ctx = self.eval_ctx
context.blocks.update((k, list(v)) for k, v in self.blocks.iteritems())
return context
@@ -159,6 +159,29 @@ def test_super_in_scoped_block(self):
'{{ super() }}|{{ item * 2 }}{% endblock %}')
assert t.render(seq=range(5)) == '[0|0][1|2][2|4][3|6][4|8]'
+ def test_scoped_block_after_inheritance(self):
+ env = Environment(loader=DictLoader({
+ 'layout.html': '''
+ {% block useless %}{% endblock %}
+ ''',
+ 'index.html': '''
+ {%- extends 'layout.html' %}
+ {% from 'helpers.html' import foo with context %}
+ {% block useless %}
+ {% for x in [1, 2, 3] %}
+ {% block testing scoped %}
+ {{ foo(x) }}
+ {% endblock %}
+ {% endfor %}
+ {% endblock %}
+ ''',
+ 'helpers.html': '''
+ {% macro foo(x) %}{{ the_foo + x }}{% endmacro %}
+ '''
+ }))
+ rv = env.get_template('index.html').render(the_foo=42).split()
+ assert rv == ['43', '44', '45']
+
class BugFixTestCase(JinjaTestCase):

0 comments on commit 5f3d661

Please sign in to comment.