1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """HTML formatting drivers for ureports"""
19 __docformat__ = "restructuredtext en"
20
21 from cgi import escape
22
23 from logilab.common.ureports import BaseWriter
24
25
27 """format layouts as HTML"""
28
32
34 """get an attribute string from layout member attributes"""
35 attrs = ''
36 klass = getattr(layout, 'klass', None)
37 if klass:
38 attrs += ' class="%s"' % klass
39 nid = getattr(layout, 'id', None)
40 if nid:
41 attrs += ' id="%s"' % nid
42 return attrs
43
50
56
57
59 """display a section as html, using div + h[section level]"""
60 self.section += 1
61 self.writeln('<div%s>' % self.handle_attrs(layout))
62 self.format_children(layout)
63 self.writeln('</div>')
64 self.section -= 1
65
71
73 """display a table as html"""
74 self.writeln('<table%s>' % self.handle_attrs(layout))
75 table_content = self.get_table_content(layout)
76 for i in range(len(table_content)):
77 row = table_content[i]
78 if i == 0 and layout.rheaders:
79 self.writeln('<tr class="header">')
80 elif i+1 == len(table_content) and layout.rrheaders:
81 self.writeln('<tr class="header">')
82 else:
83 self.writeln('<tr class="%s">' % (i%2 and 'even' or 'odd'))
84 for j in range(len(row)):
85 cell = row[j] or ' '
86 if (layout.rheaders and i == 0) or \
87 (layout.cheaders and j == 0) or \
88 (layout.rrheaders and i+1 == len(table_content)) or \
89 (layout.rcheaders and j+1 == len(row)):
90 self.writeln('<th>%s</th>' % cell)
91 else:
92 self.writeln('<td>%s</td>' % cell)
93 self.writeln('</tr>')
94 self.writeln('</table>')
95
102
108
114
116 """display links (using <a>)"""
117 self.write(' <a href="%s"%s>%s</a>' % (layout.url,
118 self.handle_attrs(layout),
119 layout.label))
120 - def visit_verbatimtext(self, layout):
121 """display verbatim text (using <pre>)"""
122 self.write('<pre>')
123 self.write(layout.data.replace('&', '&').replace('<', '<'))
124 self.write('</pre>')
125
126 - def visit_text(self, layout):
127 """add some text"""
128 data = layout.data
129 if layout.escaped:
130 data = data.replace('&', '&').replace('<', '<')
131 self.write(data)
132