From: Armin Ronacher Date: Thu, 19 Feb 2009 15:11:11 +0000 (+0100) Subject: Added proper super() support for scoped blocks. X-Git-Tag: 2.2~38 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3f1d8f18472209c61d2fff3a910d1d0290cb7dd6;p=jinja2.git Added proper super() support for scoped blocks. --HG-- branch : trunk --- diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 013d987..c2e0aa3 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -173,8 +173,10 @@ class Context(object): def derived(self, locals=None): """Internal helper function to create a derived context.""" - return new_context(self.environment, self.name, self.blocks, - self.parent, True, None, locals) + context = new_context(self.environment, self.name, {}, + self.parent, True, None, locals) + context.blocks.update((k, list(v)) for k, v in self.blocks.iteritems()) + return context def _all(meth): proxy = lambda self: getattr(self.get_all(), meth)() diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index 6a45f59..13a9d8d 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -175,3 +175,12 @@ def test_scoped_block(): })) t = env.from_string('{% extends "master.html" %}{% block item %}{{ item }}{% endblock %}') assert t.render(seq=range(5)) == '[0][1][2][3][4]' + + +def test_super_in_scoped_block(): + env = Environment(loader=DictLoader({ + 'master.html': '{% for item in seq %}[{% block item scoped %}' + '{{ item }}{% endblock %}]{% endfor %}' + })) + t = env.from_string('{% extends "master.html" %}{% block item %}{{ super() }}|{{ item * 2 }}{% endblock %}') + assert t.render(seq=range(5)) == '[0|0][1|2][2|4][3|6][4|8]'