Skip to content
Snippets Groups Projects
Commit b295167c authored by Mike Bayer's avatar Mike Bayer
Browse files

- 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]
parent 4c606b48
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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):
......
......@@ -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"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment