comparison markup/tests/template.py @ 154:8bd5c8cd33e0 trunk

* 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 cdb2a1f930e2
children 3f23fafeef99
comparison
equal deleted inserted replaced
153:fc2ff46d1ae3 154:8bd5c8cd33e0
182 ${echo('foo')} 182 ${echo('foo')}
183 </doc>""") 183 </doc>""")
184 self.assertEqual("""<doc> 184 self.assertEqual("""<doc>
185 <b>foo</b> 185 <b>foo</b>
186 </doc>""", str(tmpl.generate())) 186 </doc>""", str(tmpl.generate()))
187
188 def test_nested_defs(self):
189 """
190 Verify that a template function defined inside a conditional block can
191 be called from outside that block.
192 """
193 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
194 <py:if test="semantic">
195 <strong py:def="echo(what)">${what}</strong>
196 </py:if>
197 <py:if test="not semantic">
198 <b py:def="echo(what)">${what}</b>
199 </py:if>
200 ${echo('foo')}
201 </doc>""")
202 self.assertEqual("""<doc>
203 <strong>foo</strong>
204 </doc>""", str(tmpl.generate(semantic=True)))
187 205
188 206
189 class ForDirectiveTestCase(unittest.TestCase): 207 class ForDirectiveTestCase(unittest.TestCase):
190 """Tests for the `py:for` template directive.""" 208 """Tests for the `py:for` template directive."""
191 209
Copyright (C) 2012-2017 Edgewall Software