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 six.moves import range
24
25 from logilab.common.ureports import BaseWriter
26
27
29 """format layouts as HTML"""
30
34
36 """get an attribute string from layout member attributes"""
37 attrs = u''
38 klass = getattr(layout, 'klass', None)
39 if klass:
40 attrs += u' class="%s"' % klass
41 nid = getattr(layout, 'id', None)
42 if nid:
43 attrs += u' id="%s"' % nid
44 return attrs
45
52
58
59
61 """display a section as html, using div + h[section level]"""
62 self.section += 1
63 self.writeln(u'<div%s>' % self.handle_attrs(layout))
64 self.format_children(layout)
65 self.writeln(u'</div>')
66 self.section -= 1
67
73
75 """display a table as html"""
76 self.writeln(u'<table%s>' % self.handle_attrs(layout))
77 table_content = self.get_table_content(layout)
78 for i in range(len(table_content)):
79 row = table_content[i]
80 if i == 0 and layout.rheaders:
81 self.writeln(u'<tr class="header">')
82 elif i+1 == len(table_content) and layout.rrheaders:
83 self.writeln(u'<tr class="header">')
84 else:
85 self.writeln(u'<tr class="%s">' % (i%2 and 'even' or 'odd'))
86 for j in range(len(row)):
87 cell = row[j] or u' '
88 if (layout.rheaders and i == 0) or \
89 (layout.cheaders and j == 0) or \
90 (layout.rrheaders and i+1 == len(table_content)) or \
91 (layout.rcheaders and j+1 == len(row)):
92 self.writeln(u'<th>%s</th>' % cell)
93 else:
94 self.writeln(u'<td>%s</td>' % cell)
95 self.writeln(u'</tr>')
96 self.writeln(u'</table>')
97
104
110
116
118 """display links (using <a>)"""
119 self.write(u' <a href="%s"%s>%s</a>' % (layout.url,
120 self.handle_attrs(layout),
121 layout.label))
122 - def visit_verbatimtext(self, layout):
123 """display verbatim text (using <pre>)"""
124 self.write(u'<pre>')
125 self.write(layout.data.replace(u'&', u'&').replace(u'<', u'<'))
126 self.write(u'</pre>')
127
128 - def visit_text(self, layout):
129 """add some text"""
130 data = layout.data
131 if layout.escaped:
132 data = data.replace(u'&', u'&').replace(u'<', u'<')
133 self.write(data)
134