function to make generation of a simple sgml tag
authorsylvain.thenault@logilab.fr
Fri, 30 Jan 2009 14:39:56 +0100
changeset 525 bd4e03297cf0
parent 524 eee3983e29e9
child 526 498ff2e16fae
function to make generation of a simple sgml tag
common/uilib.py
--- 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 '#'