changeset 185:95c3813a00de trunk

Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
author cmlenz
date Tue, 22 Aug 2006 14:52:44 +0000
parents 181d292eafa2
children 3d8501e292d1
files ChangeLog markup/template.py markup/tests/template.py
diffstat 3 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,6 +33,8 @@
    (ticket #31).
  * Expressions in templates can now span multiple lines if they are enclosed
    in curly braces.
+ * py:def macros can now be invoked from within expressions inside attribute
+   values (ticket #34).
 
 
 Version 0.1
--- a/markup/template.py
+++ b/markup/template.py
@@ -910,12 +910,11 @@
                         value = substream
                     else:
                         values = []
-                        for subkind, subdata, subpos in substream:
-                            if subkind is EXPR:
-                                values.append(subdata.evaluate(ctxt))
-                            else:
+                        for subkind, subdata, subpos in self._eval(substream,
+                                                                   ctxt):
+                            if subkind is TEXT:
                                 values.append(subdata)
-                        value = [unicode(x) for x in values if x is not None]
+                        value = [x for x in values if x is not None]
                         if not value:
                             continue
                     new_attrib.append((name, u''.join(value)))
--- a/markup/tests/template.py
+++ b/markup/tests/template.py
@@ -261,6 +261,24 @@
           foo
         </doc>""", str(tmpl.generate()))
 
+    def test_invocation_in_attribute(self):
+        tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
+          <py:def function="echo(what)">${what or 'something'}</py:def>
+          <p class="${echo('foo')}">bar</p>
+        </doc>""")
+        self.assertEqual("""<doc>
+          <p class="foo">bar</p>
+        </doc>""", str(tmpl.generate()))
+
+    def test_invocation_in_attribute_none(self):
+        tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
+          <py:def function="echo()">${None}</py:def>
+          <p class="${echo()}">bar</p>
+        </doc>""")
+        self.assertEqual("""<doc>
+          <p>bar</p>
+        </doc>""", str(tmpl.generate()))
+
 
 class ForDirectiveTestCase(unittest.TestCase):
     """Tests for the `py:for` template directive."""
Copyright (C) 2012-2017 Edgewall Software