author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 21 Jan 2010 10:42:37 +0100 | |
changeset 4304 | 0b53e850cdb5 |
parent 4252 | 6c4f109c2b03 |
child 5421 | 8167de96c523 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3847
diff
changeset
|
4 |
:copyright: 2010 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 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3847
diff
changeset
|
10 |
from cubicweb.uilib import simple_sgml_tag, sgml_attributes |
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 |
||
3803
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2517
diff
changeset
|
21 |
button = tag('button') |
845 | 22 |
input = tag('input') |
23 |
textarea = tag('textarea') |
|
24 |
a = tag('a') |
|
25 |
span = tag('span') |
|
1623 | 26 |
div = tag('div', False) |
845 | 27 |
img = tag('img') |
846 | 28 |
label = tag('label') |
895
e78ae38506db
select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
861
diff
changeset
|
29 |
option = tag('option') |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
30 |
h1 = tag('h1') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
31 |
h2 = tag('h2') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
32 |
h3 = tag('h3') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
33 |
h4 = tag('h4') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
34 |
h5 = tag('h5') |
3847
7cf2b338a8e7
[common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3803
diff
changeset
|
35 |
tr = tag('tr') |
7cf2b338a8e7
[common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3803
diff
changeset
|
36 |
th = tag('th') |
7cf2b338a8e7
[common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3803
diff
changeset
|
37 |
td = tag('td') |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
38 |
|
1054 | 39 |
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
|
40 |
if multiple: |
909
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
41 |
attrs['multiple'] = 'multiple' |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
42 |
if id: |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
43 |
attrs['id'] = id |
1647
9936aca2453d
sort attribute for testing purpose
sylvain.thenault@logilab.fr
parents:
1623
diff
changeset
|
44 |
attrs['name'] = name |
2517
d664652b7f9c
select attributes should be escaped
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
html = [u'<select %s>' % sgml_attributes(attrs)] |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
46 |
html += options |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
47 |
html.append(u'</select>') |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
48 |
return u'\n'.join(html) |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
49 |