more tags, map klass -> class avoiding needs to use **dict tls-sprint
authorsylvain.thenault@logilab.fr
Fri, 27 Feb 2009 16:16:33 +0100
branchtls-sprint
changeset 980 59552ba2015f
parent 947 01f5001304b2
child 981 d86d1ee3b60e
more tags, map klass -> class avoiding needs to use **dict
common/tags.py
common/uilib.py
--- a/common/tags.py	Tue Feb 24 17:20:04 2009 +0100
+++ b/common/tags.py	Fri Feb 27 16:16:33 2009 +0100
@@ -1,5 +1,13 @@
-from logilab.mtconverter import html_escape
+"""helper classes to generate simple (X)HTML tags
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+"""
+__docformat__ = "restructuredtext en"
+
 from cubicweb.common.uilib import simple_sgml_tag
+
 class tag(object):
     def __init__(self, name):
         self.name = name
@@ -14,6 +22,11 @@
 img = tag('img')
 label = tag('label')
 option = tag('option')
+h1 = tag('h1')
+h2 = tag('h2')
+h3 = tag('h3')
+h4 = tag('h4')
+h5 = tag('h5')
 
 def select(name, id=None, multiple=False, options=[]):
     attrs = {}
@@ -21,8 +34,8 @@
         attrs['multiple'] = 'multiple'
     if id:
         attrs['id'] = id
-    html = [u'<select name="%s" %s>' % (name,
-                                        ' '.join('%s="%s"' % kv for kv in attrs.items()))]
+    html = [u'<select name="%s" %s>' % (
+        name, ' '.join('%s="%s"' % kv for kv in attrs.items()))]
     html += options
     html.append(u'</select>')
     return u'\n'.join(html)
--- a/common/uilib.py	Tue Feb 24 17:20:04 2009 +0100
+++ b/common/uilib.py	Fri Feb 27 16:16:33 2009 +0100
@@ -209,6 +209,10 @@
     """
     value = u'<%s' % tag
     if attrs:
+        try:
+            attrs['class'] = attrs.pop('klass')
+        except KeyError:
+            pass
         value += u' ' + u' '.join(u'%s="%s"' % (attr, html_escape(unicode(value)))
                                   for attr, value in attrs.items()
                                   if value is not None)