diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-16 13:02:51 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-16 13:02:51 -0500 |
commit | 2879f8bcc02d75d256bf7db97251a8708ef2466e (patch) | |
tree | b64ad6ab41312ce66147818802e218a8057e50e7 /test/test_cache.py | |
parent | 3266c0160d9103703400123b81a713db21ccd5be (diff) | |
download | external_python_mako-2879f8bcc02d75d256bf7db97251a8708ef2466e.tar.gz external_python_mako-2879f8bcc02d75d256bf7db97251a8708ef2466e.tar.bz2 external_python_mako-2879f8bcc02d75d256bf7db97251a8708ef2466e.zip |
- [feature/bug] Can now refer to context variables
within extra arguments to <%block>, <%def>, i.e.
<%block name="foo" cache_key="${somekey}">.
Filters can also be used in this way, i.e.
<%def name="foo()" filter="myfilter">
then template.render(myfilter=some_callable)
[ticket:180]
Diffstat (limited to 'test/test_cache.py')
-rw-r--r-- | test/test_cache.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_cache.py b/test/test_cache.py index d898b02..1c7b42a 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -139,6 +139,37 @@ class CacheTest(TemplateTest): ] assert m.kwargs == {} + def test_dynamic_key_with_context(self): + t = Template(""" + <%block name="foo" cached="True" cache_key="${mykey}"> + some block + </%block> + """) + m = self._install_mock_cache(t) + t.render(mykey="thekey") + t.render(mykey="thekey") + eq_( + result_lines(t.render(mykey="thekey")), + ["some block"] + ) + eq_(m.key, "thekey") + + t = Template(""" + <%def name="foo()" cached="True" cache_key="${mykey}"> + some def + </%def> + ${foo()} + """) + m = self._install_mock_cache(t) + t.render(mykey="thekey") + t.render(mykey="thekey") + eq_( + result_lines(t.render(mykey="thekey")), + ["some def"] + ) + eq_(m.key, "thekey") + + def test_dynamic_key_with_funcargs(self): t = Template(""" <%def name="foo(num=5)" cached="True" cache_key="foo_${str(num)}"> |