1 """HTML formatting drivers for ureports.
2
3 :copyright:
4 2004-2008 `LOGILAB S.A. <http://www.logilab.fr>`_ (Paris, FRANCE),
5 all rights reserved.
6
7 :contact:
8 http://www.logilab.org/project/logilab-common --
9 mailto:python-projects@logilab.org
10
11 :license:
12 `General Public License version 2
13 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>`_
14 """
15 __docformat__ = "restructuredtext en"
16
17 from cgi import escape
18
19 from logilab.common.ureports import BaseWriter
20
21
23 """format layouts as HTML"""
24
28
30 """get an attribute string from layout member attributes"""
31 attrs = ''
32 klass = getattr(layout, 'klass', None)
33 if klass:
34 attrs += ' class="%s"' % klass
35 nid = getattr(layout, 'id', None)
36 if nid:
37 attrs += ' id="%s"' % nid
38 return attrs
39
46
52
53
55 """display a section as html, using div + h[section level]"""
56 self.section += 1
57 self.writeln('<div%s>' % self.handle_attrs(layout))
58 self.format_children(layout)
59 self.writeln('</div>')
60 self.section -= 1
61
67
69 """display a table as html"""
70 self.writeln('<table%s>' % self.handle_attrs(layout))
71 table_content = self.get_table_content(layout)
72 for i in range(len(table_content)):
73 row = table_content[i]
74 if i == 0 and layout.rheaders:
75 self.writeln('<tr class="header">')
76 elif i+1 == len(table_content) and layout.rrheaders:
77 self.writeln('<tr class="header">')
78 else:
79 self.writeln('<tr class="%s">' % (i%2 and 'even' or 'odd'))
80 for j in range(len(row)):
81 cell = row[j] or ' '
82 if (layout.rheaders and i == 0) or \
83 (layout.cheaders and j == 0) or \
84 (layout.rrheaders and i+1 == len(table_content)) or \
85 (layout.rcheaders and j+1 == len(row)):
86 self.writeln('<th>%s</th>' % cell)
87 else:
88 self.writeln('<td>%s</td>' % cell)
89 self.writeln('</tr>')
90 self.writeln('</table>')
91
98
104
110
112 """display links (using <a>)"""
113 self.write(' <a href="%s"%s>%s</a>' % (layout.url,
114 self.handle_attrs(layout),
115 layout.label))
116 - def visit_verbatimtext(self, layout):
117 """display verbatim text (using <pre>)"""
118 self.write('<pre>')
119 self.write(layout.data.replace('&', '&').replace('<', '<'))
120 self.write('</pre>')
121
122 - def visit_text(self, layout):
123 """add some text"""
124 data = layout.data
125 if layout.escaped:
126 data = data.replace('&', '&').replace('<', '<')
127 self.write(data)
128