common/uilib.py
changeset 525 bd4e03297cf0
parent 362 a6a319f000c3
child 708 b4728112625f
child 927 bfcc610c3d5e
--- a/common/uilib.py	Fri Jan 30 14:38:16 2009 +0100
+++ b/common/uilib.py	Fri Jan 30 14:39:56 2009 +0100
@@ -4,7 +4,7 @@
 contains some functions designed to help implementation of cubicweb user interface
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -213,6 +213,21 @@
     
 # HTML generation helper functions ############################################
 
+def simple_sgml_tag(tag, content=None, **attrs):
+    """generation of a simple sgml tag (eg without children tags) easier
+
+    content and attributes will be escaped
+    """
+    value = u'<%s' % tag
+    if attrs:
+        value += u' ' + u' '.join(u'%s="%s"' % (attr, html_escape(unicode(value)))
+                                  for attr, value in attrs.items())
+    if content:
+        value += u'>%s</%s>' % (html_escape(unicode(content)), tag)
+    else:
+        value += u'/>'
+    return value
+
 def tooltipize(text, tooltip, url=None):
     """make an HTML tooltip"""
     url = url or '#'