From b295167c5a3a4d880b75f8bfd9aa0b296b876bd3 Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Fri, 5 Mar 2010 17:07:39 +0000
Subject: [PATCH] - The <%page args> tag can now be used in a base   inheriting
 template - the full set of render()   arguments are passed down through the
 inherits   chain.  Undeclared arguments go into **pageargs   as usual. 
 [ticket:116]

---
 CHANGES               |  6 +++++
 mako/runtime.py       |  3 ++-
 test/test_template.py | 53 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/CHANGES b/CHANGES
index b490f90..2de917e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,12 @@
  
 - Template accepts empty control structure, i.e.
   % if: %endif, etc. [ticket:94]
+
+- The <%page args> tag can now be used in a base 
+  inheriting template - the full set of render()
+  arguments are passed down through the inherits
+  chain.  Undeclared arguments go into **pageargs
+  as usual.  [ticket:116]
   
 0.2.6
 
diff --git a/mako/runtime.py b/mako/runtime.py
index 19d79de..f59a8bc 100644
--- a/mako/runtime.py
+++ b/mako/runtime.py
@@ -314,6 +314,7 @@ def _decorate_inline(context, fn):
             
 def _include_file(context, uri, calling_uri, **kwargs):
     """locate the template from the given uri and include it in the current output."""
+    
     template = _lookup_template(context, uri, calling_uri)
     (callable_, ctx) = _populate_self_namespace(context._clean_inheritance_tokens(), template)
     callable_(ctx, **_kwargs_for_callable(callable_, context._orig, **kwargs))
@@ -377,7 +378,7 @@ def _render(template, callable_, args, data, as_unicode=False):
     context = Context(buf, **data)
     context._outputting_as_unicode = as_unicode
     context._with_template = template
-    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))
+    _render_context(template, callable_, context, *args, **data)
     return context._pop_buffer().getvalue()
 
 def _kwargs_for_callable(callable_, data, **kwargs):
diff --git a/test/test_template.py b/test/test_template.py
index 204ee3b..c738012 100644
--- a/test/test_template.py
+++ b/test/test_template.py
@@ -369,7 +369,60 @@ class PageArgsTest(TemplateTest):
             assert False
         except TypeError, e:
             assert True
+    
+    def test_inherits(self):
+        lookup = TemplateLookup()
+        lookup.put_string("base.tmpl",
+        """
+        <%page args="bar" />
+        ${bar}
+        ${pageargs['foo']}
+        ${self.body(**pageargs)}
+        """
+        )
+        lookup.put_string("index.tmpl", """
+        <%inherit file="base.tmpl" />
+        <%page args="variable" />
+        ${variable}
+        """)
 
+        self._do_test(
+            lookup.get_template("index.tmpl"),
+            "bar foo var",
+            filters=flatten_result,
+            template_args={'variable':'var', 'bar':'bar', 'foo':'foo'}
+            
+        )
+
+    def test_includes(self):
+        lookup = TemplateLookup()
+        lookup.put_string("incl1.tmpl",
+        """
+        <%page args="bar" />
+        ${bar}
+        ${pageargs['foo']}
+        """
+        )
+        lookup.put_string("incl2.tmpl",
+        """
+        ${pageargs}
+        """
+        )
+        lookup.put_string("index.tmpl", """
+        <%include file="incl1.tmpl" args="**pageargs"/>
+        <%page args="variable" />
+        ${variable}
+        <%include file="incl2.tmpl" />
+        """)
+
+        self._do_test(
+            lookup.get_template("index.tmpl"),
+            "bar foo var {}",
+            filters=flatten_result,
+            template_args={'variable':'var', 'bar':'bar', 'foo':'foo'}
+
+        )
+        
     def test_with_context(self):
         template = Template("""
             <%page args="x, y, z=7"/>
-- 
GitLab