|
1 """helper classes to generate simple (X)HTML tags |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
|
7 """ |
|
8 __docformat__ = "restructuredtext en" |
|
9 |
|
10 from cubicweb.uilib import simple_sgml_tag, sgml_attributes |
|
11 |
|
12 class tag(object): |
|
13 def __init__(self, name, escapecontent=True): |
|
14 self.name = name |
|
15 self.escapecontent = escapecontent |
|
16 |
|
17 def __call__(self, __content=None, **attrs): |
|
18 attrs.setdefault('escapecontent', self.escapecontent) |
|
19 return simple_sgml_tag(self.name, __content, **attrs) |
|
20 |
|
21 button = tag('button') |
|
22 input = tag('input') |
|
23 textarea = tag('textarea') |
|
24 a = tag('a') |
|
25 span = tag('span') |
|
26 div = tag('div', False) |
|
27 img = tag('img') |
|
28 label = tag('label') |
|
29 option = tag('option') |
|
30 h1 = tag('h1') |
|
31 h2 = tag('h2') |
|
32 h3 = tag('h3') |
|
33 h4 = tag('h4') |
|
34 h5 = tag('h5') |
|
35 tr = tag('tr') |
|
36 th = tag('th') |
|
37 td = tag('td') |
|
38 |
|
39 def select(name, id=None, multiple=False, options=[], **attrs): |
|
40 if multiple: |
|
41 attrs['multiple'] = 'multiple' |
|
42 if id: |
|
43 attrs['id'] = id |
|
44 attrs['name'] = name |
|
45 html = [u'<select %s>' % sgml_attributes(attrs)] |
|
46 html += options |
|
47 html.append(u'</select>') |
|
48 return u'\n'.join(html) |
|
49 |