author | sylvain.thenault@logilab.fr |
Wed, 15 Apr 2009 14:06:08 +0200 | |
branch | tls-sprint |
changeset 1356 | 7b4802822f40 |
parent 1065 | 0a37f90acb13 |
child 1623 | 0b974e21d762 |
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 |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
4 |
:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
6 |
""" |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
7 |
__docformat__ = "restructuredtext en" |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
8 |
|
845 | 9 |
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
|
10 |
|
845 | 11 |
class tag(object): |
12 |
def __init__(self, name): |
|
13 |
self.name = name |
|
14 |
||
15 |
def __call__(self, __content=None, **attrs): |
|
16 |
return simple_sgml_tag(self.name, __content, **attrs) |
|
17 |
||
18 |
input = tag('input') |
|
19 |
textarea = tag('textarea') |
|
20 |
a = tag('a') |
|
21 |
span = tag('span') |
|
1065 | 22 |
div = tag('div') |
845 | 23 |
img = tag('img') |
846 | 24 |
label = tag('label') |
895
e78ae38506db
select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
861
diff
changeset
|
25 |
option = tag('option') |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
26 |
h1 = tag('h1') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
27 |
h2 = tag('h2') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
28 |
h3 = tag('h3') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
29 |
h4 = tag('h4') |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
30 |
h5 = tag('h5') |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
31 |
|
1054 | 32 |
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
|
33 |
if multiple: |
909
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
34 |
attrs['multiple'] = 'multiple' |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
35 |
if id: |
4685a8c21d73
select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
895
diff
changeset
|
36 |
attrs['id'] = id |
980
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
37 |
html = [u'<select name="%s" %s>' % ( |
59552ba2015f
more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents:
909
diff
changeset
|
38 |
name, ' '.join('%s="%s"' % kv for kv in attrs.items()))] |
861
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
39 |
html += options |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
40 |
html.append(u'</select>') |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
41 |
return u'\n'.join(html) |
7985b5db2284
provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
846
diff
changeset
|
42 |