diff markup/tests/template.py @ 154:1c404be518d1

* Make sure `py:def` macros don't go out of scope if they are defined inside another directive. * Cleaned up the `DefDirective` implementation a bit.
author cmlenz
date Wed, 16 Aug 2006 14:04:30 +0000
parents 064ba1078f92
children 8e81177059f3
line wrap: on
line diff
--- a/markup/tests/template.py
+++ b/markup/tests/template.py
@@ -185,6 +185,24 @@
             <b>foo</b>
         </doc>""", str(tmpl.generate()))
 
+    def test_nested_defs(self):
+        """
+        Verify that a template function defined inside a conditional block can
+        be called from outside that block.
+        """
+        tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
+          <py:if test="semantic">
+            <strong py:def="echo(what)">${what}</strong>
+          </py:if>
+          <py:if test="not semantic">
+            <b py:def="echo(what)">${what}</b>
+          </py:if>
+          ${echo('foo')}
+        </doc>""")
+        self.assertEqual("""<doc>
+          <strong>foo</strong>
+        </doc>""", str(tmpl.generate(semantic=True)))
+
 
 class ForDirectiveTestCase(unittest.TestCase):
     """Tests for the `py:for` template directive."""
Copyright (C) 2012-2017 Edgewall Software