# HG changeset patch
# User cmlenz
# Date 1156258364 0
# Node ID 95c3813a00dec3024c4edf76a1939a9c5b7e7651
# Parent 181d292eafa2ed62e7fe5a9dbf3040abbb9e97b9
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
diff --git a/ChangeLog b/ChangeLog
--- 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
diff --git a/markup/template.py b/markup/template.py
--- 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)))
diff --git a/markup/tests/template.py b/markup/tests/template.py
--- a/markup/tests/template.py
+++ b/markup/tests/template.py
@@ -261,6 +261,24 @@
foo
""", str(tmpl.generate()))
+ def test_invocation_in_attribute(self):
+ tmpl = Template("""
+ ${what or 'something'}
+ bar
+ """)
+ self.assertEqual("""
+ bar
+ """, str(tmpl.generate()))
+
+ def test_invocation_in_attribute_none(self):
+ tmpl = Template("""
+ ${None}
+ bar
+ """)
+ self.assertEqual("""
+ bar
+ """, str(tmpl.generate()))
+
class ForDirectiveTestCase(unittest.TestCase):
"""Tests for the `py:for` template directive."""