aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-05 17:07:39 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-05 17:07:39 +0000
commitb295167c5a3a4d880b75f8bfd9aa0b296b876bd3 (patch)
treeaad815bde3c50071fba08af239ac7bf8bb1c0f0d
parent4c606b484bd2c2a191b4ce0d6a28061d33b0e66c (diff)
downloadexternal_python_mako-b295167c5a3a4d880b75f8bfd9aa0b296b876bd3.tar.gz
external_python_mako-b295167c5a3a4d880b75f8bfd9aa0b296b876bd3.tar.bz2
external_python_mako-b295167c5a3a4d880b75f8bfd9aa0b296b876bd3.zip
- 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]
-rw-r--r--CHANGES6
-rw-r--r--mako/runtime.py3
-rw-r--r--test/test_template.py53
3 files changed, 61 insertions, 1 deletions
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"/>