# HG changeset patch # User cmlenz # Date 1156258364 0 # Node ID 8e5a3048b359c7f594802d9762f47aca4396f46b # Parent e27a48802987dd3e17b6ead737330f53a9261e98 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."""