author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 16 Jul 2009 17:00:55 +0200 | |
changeset 2387 | ea1defea9636 |
parent 1977 | 606923dff11b |
child 2517 | d664652b7f9c |
permissions | -rw-r--r-- |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
1 |
"""helper classes to generate simple (X)HTML tags |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
2 |
|
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
3 |
:organization: Logilab |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1647
diff
changeset
|
4 |
:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1647
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
7 |
""" |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
9 |
|
845 | 10 |
from cubicweb.common.uilib import simple_sgml_tag |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
11 |
|
845 | 12 |
class tag(object): |
1623 | 13 |
def __init__(self, name, escapecontent=True): |
845 | 14 |
self.name = name |
1623 | 15 |
self.escapecontent = escapecontent |
16 |
||
845 | 17 |
def __call__(self, __content=None, **attrs): |
1623 | 18 |
attrs.setdefault('escapecontent', self.escapecontent) |
845 | 19 |
return simple_sgml_tag(self.name, __content, **attrs) |
20 |
||
21 |
input = tag('input') |
|
22 |
textarea = tag('textarea') |
|
23 |
a = tag('a') |
|
24 |
span = tag('span') |
|
1623 | 25 |
div = tag('div', False) |
845 | 26 |
img = tag('img') |
846 | 27 |
label = tag('label') |
895
e78ae38506db
select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
861
diff
changeset
|
28 |
option = tag('option') |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
29 |
h1 = tag('h1') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
30 |
h2 = tag('h2') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
31 |
h3 = tag('h3') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
32 |
h4 = tag('h4') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
33 |
h5 = tag('h5') |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
34 |
|
1054 | 35 |
def select(name, id=None, multiple=False, options=[], **attrs): |
895
e78ae38506db
select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
861
diff
changeset
|
36 |
if multiple: |
909
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
37 |
attrs['multiple'] = 'multiple' |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
38 |
if id: |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
39 |
attrs['id'] = id |
1647
9936aca2453d
sort attribute for testing purpose
sylvain.thenault@logilab.fr
parents:
1623
diff
changeset
|
40 |
attrs['name'] = name |
9936aca2453d
sort attribute for testing purpose
sylvain.thenault@logilab.fr
parents:
1623
diff
changeset
|
41 |
html = [u'<select %s>' % ' '.join('%s="%s"' % kv |
9936aca2453d
sort attribute for testing purpose
sylvain.thenault@logilab.fr
parents:
1623
diff
changeset
|
42 |
for kv in sorted(attrs.items()))] |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
43 |
html += options |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
44 |
html.append(u'</select>') |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
45 |
return u'\n'.join(html) |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
46 |