tags.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """helper classes to generate simple (X)HTML tags"""
       
    19 
       
    20 __docformat__ = "restructuredtext en"
       
    21 
       
    22 from cubicweb.uilib import simple_sgml_tag, sgml_attributes
       
    23 
       
    24 class tag(object):
       
    25     def __init__(self, name, escapecontent=True):
       
    26         self.name = name
       
    27         self.escapecontent = escapecontent
       
    28 
       
    29     def __call__(self, __content=None, **attrs):
       
    30         attrs.setdefault('escapecontent', self.escapecontent)
       
    31         return simple_sgml_tag(self.name, __content, **attrs)
       
    32 
       
    33 button = tag('button')
       
    34 input = tag('input')
       
    35 textarea = tag('textarea')
       
    36 a = tag('a')
       
    37 span = tag('span')
       
    38 div = tag('div', False)
       
    39 img = tag('img')
       
    40 label = tag('label')
       
    41 option = tag('option')
       
    42 h1 = tag('h1')
       
    43 h2 = tag('h2')
       
    44 h3 = tag('h3')
       
    45 h4 = tag('h4')
       
    46 h5 = tag('h5')
       
    47 tr = tag('tr')
       
    48 th = tag('th')
       
    49 td = tag('td')
       
    50 iframe = tag('iframe')
       
    51 
       
    52 def select(name, id=None, multiple=False, options=[], **attrs):
       
    53     if multiple:
       
    54         attrs['multiple'] = 'multiple'
       
    55     if id:
       
    56         attrs['id'] = id
       
    57     attrs['name'] = name
       
    58     html = [u'<select %s>' % sgml_attributes(attrs)]
       
    59     html += options
       
    60     html.append(u'</select>')
       
    61     return u'\n'.join(html)