changeset 48:06c642ba2b08

convert the result of expressions in attributes to strings so that values like ints are output correctly
author mgood
date Tue, 04 Jul 2006 04:49:22 +0000
parents 04bb078c6234
children 9b5255d72e33
files examples/trac/templates/about.html markup/template.py markup/tests/template.py
diffstat 3 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/examples/trac/templates/about.html
+++ b/examples/trac/templates/about.html
@@ -41,7 +41,7 @@
             <div py:for="section in about.config" py:strip="">
             <tr py:for="idx,option in enumerate(section.options)">
               <th py:if="idx == 0" class="section"
-                  rowspan="${str(len(section.options))}">
+                  rowspan="${len(section.options)}">
                   ${section.name}</th>
               <td class="name">${option.name}</td>
               <td class="${option.valueclass}">${option.value}</td>
@@ -72,7 +72,7 @@
             </tr>
             <tr py:for="idx,extension_point in enumerate(plugin.extension_points)">
               <th py:if="idx == 0" class="xtnpts"
-                  rowspan="${str(len(plugin.extension_points))}">
+                  rowspan="${len(plugin.extension_points)}">
                 Extension points:
               </th>
               <td class="xtnpts">        
--- a/markup/template.py
+++ b/markup/template.py
@@ -33,7 +33,6 @@
  * Improved error reporting
  * Support for using directives as elements and not just as attributes, reducing
    the need for wrapper elements with py:strip=""
- * Support for py:choose/py:when/py:otherwise (similar to XSLT)
  * Support for list comprehensions and generator expressions in expressions
 
 Random thoughts:
@@ -804,7 +803,7 @@
                                 values.append(subdata.evaluate(ctxt))
                             else:
                                 values.append(subdata)
-                        value = filter(lambda x: x is not None, values)
+                        value = [unicode(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
@@ -166,6 +166,11 @@
         self.assertEqual(Stream.TEXT, parts[2][0])
         self.assertEqual(' baz', parts[2][1])
 
+    def test_interpolate_non_string_attrs(self):
+        ctxt = Context()
+        tmpl = Template('<root attr="${1}"/>')
+        self.assertEqual('<root attr="1"/>', str(tmpl.generate(ctxt)))
+
     def test_bad_directive_error(self):
         xml = '<p xmlns:py="http://purl.org/kid/ns#" py:do="nothing" />'
         try:
Copyright (C) 2012-2017 Edgewall Software