diff markup/template.py @ 5:dbb08edbc615 trunk

Improved `py:attrs` directive so that it removes existing attributes if they evaluate to `None` (AFAICT matching Kid behavior).
author cmlenz
date Sat, 03 Jun 2006 15:29:27 +0000
parents 5479aae32f5a
children 71e8e645fe81
line wrap: on
line diff
--- a/markup/template.py
+++ b/markup/template.py
@@ -30,7 +30,6 @@
    nodes, making match templates more powerful while keeping the syntax simple
 
 Todo items:
- * XPath support needs a real implementation
  * Improved error reporting
  * Support for using directives as elements and not just as attributes, reducing
    the need for wrapper elements with py:strip=""
@@ -210,12 +209,15 @@
         kind, (tag, attrib), pos  = stream.next()
         attrs = self.expr.evaluate(ctxt)
         if attrs:
-            attrib = attrib[:]
-            for name, value in attrs.items():
-                if value is not None:
-                    value = unicode(value).strip()
-                    attrib.append((name, value))
-        yield kind, (tag, Attributes(attrib)), pos
+            attrib = Attributes(attrib[:])
+            if not isinstance(attrs, list): # assume it's a dict
+                attrs = attrs.items()
+            for name, value in attrs:
+                if value is None:
+                    attrib.remove(name)
+                else:
+                    attrib.set(name, unicode(value).strip())
+        yield kind, (tag, attrib), pos
         for event in stream:
             yield event
 
Copyright (C) 2012-2017 Edgewall Software