author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 30 Jun 2010 12:27:51 +0200 | |
branch | stable |
changeset 5839 | 53cbdc5e0426 |
parent 5424 | 8ecbcbff9777 |
child 6048 | 4695b1ee58a0 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <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
|
18 |
"""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
|
19 |
|
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
20 |
""" |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
21 |
__docformat__ = "restructuredtext en" |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
22 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3847
diff
changeset
|
23 |
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
|
24 |
|
845 | 25 |
class tag(object): |
1623 | 26 |
def __init__(self, name, escapecontent=True): |
845 | 27 |
self.name = name |
1623 | 28 |
self.escapecontent = escapecontent |
29 |
||
845 | 30 |
def __call__(self, __content=None, **attrs): |
1623 | 31 |
attrs.setdefault('escapecontent', self.escapecontent) |
845 | 32 |
return simple_sgml_tag(self.name, __content, **attrs) |
33 |
||
3803
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2517
diff
changeset
|
34 |
button = tag('button') |
845 | 35 |
input = tag('input') |
36 |
textarea = tag('textarea') |
|
37 |
a = tag('a') |
|
38 |
span = tag('span') |
|
1623 | 39 |
div = tag('div', False) |
845 | 40 |
img = tag('img') |
846 | 41 |
label = tag('label') |
895
e78ae38506db
select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
861
diff
changeset
|
42 |
option = tag('option') |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
43 |
h1 = tag('h1') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
44 |
h2 = tag('h2') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
45 |
h3 = tag('h3') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
46 |
h4 = tag('h4') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
47 |
h5 = tag('h5') |
3847
7cf2b338a8e7
[common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3803
diff
changeset
|
48 |
tr = tag('tr') |
7cf2b338a8e7
[common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3803
diff
changeset
|
49 |
th = tag('th') |
7cf2b338a8e7
[common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3803
diff
changeset
|
50 |
td = tag('td') |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
51 |
|
1054 | 52 |
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
|
53 |
if multiple: |
909
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
54 |
attrs['multiple'] = 'multiple' |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
55 |
if id: |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
56 |
attrs['id'] = id |
1647
9936aca2453d
sort attribute for testing purpose
sylvain.thenault@logilab.fr
parents:
1623
diff
changeset
|
57 |
attrs['name'] = name |
2517
d664652b7f9c
select attributes should be escaped
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
58 |
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
|
59 |
html += options |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
60 |
html.append(u'</select>') |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
61 |
return u'\n'.join(html) |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
62 |