summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-08-05 17:42:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-08-05 17:42:31 -0400
commit293531b5e4eac04c4e8364712137c24c4d1165f3 (patch)
treee29dcd3c875b6eaf56449064c8e9c6d7db87b6a3
parent4f554cb3f613ed8910ea3524a0787b3b726ea6ae (diff)
downloadmako-293531b5e4eac04c4e8364712137c24c4d1165f3.tar.gz
- Fixed bug regarding <%call>/def calls w/ contentrel_0_4_2
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]
-rw-r--r--CHANGES6
-rw-r--r--mako/codegen.py4
-rw-r--r--test/test_call.py57
3 files changed, 65 insertions, 2 deletions
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 @@ class _GenerateRenderMethod(object):
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 @@ class CallTest(TemplateTest):
''')
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()">