- Fixed bug regarding <%call>/def calls w/ content whereby the identity of the "caller" callable inside the <%def> would be corrupted by the presence of another <%call> in the same block. [ticket:170]
diff --git a/CHANGES b/CHANGES index 6dfc012..a6bae66 100644 --- a/CHANGES +++ b/CHANGES
@@ -1,4 +1,10 @@ 0.4.2 +- Fixed bug regarding <%call>/def calls w/ content + whereby the identity of the "caller" callable + inside the <%def> would be corrupted by the + presence of another <%call> in the same block. + [ticket:170] + - Fixed the babel plugin to accommodate <%block> [ticket:169]
diff --git a/mako/codegen.py b/mako/codegen.py index 5369180..b8c6382 100644 --- a/mako/codegen.py +++ b/mako/codegen.py
@@ -847,10 +847,10 @@ self.printer.writelines( # get local reference to current caller, if any - "caller = context.caller_stack._get_caller()", + "__M_caller = context.caller_stack._get_caller()", # push on caller for nested call "context.caller_stack.nextcaller = " - "runtime.Namespace('caller', context, callables=ccall(caller))", + "runtime.Namespace('caller', context, callables=ccall(__M_caller))", "try:") self.write_source_comment(node) self.printer.writelines(
diff --git a/test/test_call.py b/test/test_call.py index 6aadf62..5f13e95 100644 --- a/test/test_call.py +++ b/test/test_call.py
@@ -279,6 +279,63 @@ ''') assert flatten_result(template.render()) == "foo" + def test_nested_call_4(self): + base = """ + <%def name="A()"> + A_def + ${caller.body()} + </%def> + + <%def name="B()"> + B_def + ${caller.body()} + </%def> + """ + + template = Template(base + """ + <%def name="C()"> + C_def + <%self:B> + <%self:A> + A_body + </%self:A> + B_body + ${caller.body()} + </%self:B> + </%def> + + <%self:C> + C_body + </%self:C> + """) + + eq_( + flatten_result(template.render()), + "C_def B_def A_def A_body B_body C_body" + ) + + template = Template(base + """ + <%def name="C()"> + C_def + <%self:B> + B_body + ${caller.body()} + <%self:A> + A_body + </%self:A> + </%self:B> + </%def> + + <%self:C> + C_body + </%self:C> + """) + + eq_( + flatten_result(template.render()), + "C_def B_def B_body C_body A_def A_body" + ) + def test_chained_call_in_nested(self): t = Template(""" <%def name="embedded()">