Skip to content

Commit ce37b42

Browse files
committed
Merge pull request #17 from bukzor/htmlv2-style
Htmlv2 style
2 parents 0f56008 + 3f06c65 commit ce37b42

File tree

5 files changed

+596
-144
lines changed

5 files changed

+596
-144
lines changed

libcpychecker_html/extlib/prefixfree-1.0.4.min.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

libcpychecker_html/make_html.py

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from . import capi
3131

3232
from lxml.html import (
33-
tostring, fragment_fromstring as parse, builder as E
33+
tostring, fragment_fromstring as parse, builder as E
3434
)
3535

3636
from pygments import highlight
@@ -41,13 +41,13 @@
4141
from itertools import islice
4242

4343

44-
def open(filename, mode='r'):
44+
def open(filename, mode='r'): # pylint:disable=redefined-builtin
4545
"""All files are treated as UTF-8, unless explicitly binary."""
46-
from io import open
46+
import io
4747
if 'b' in mode:
48-
return open(filename, mode)
48+
return io.open(filename, mode)
4949
else:
50-
return open(filename, mode, encoding='UTF-8')
50+
return io.open(filename, mode, encoding='UTF-8')
5151

5252

5353
class HtmlPage(object):
@@ -80,20 +80,6 @@ def head(self):
8080
)
8181
for css in ('extlib/reset-20110126.min', 'pygments_c', 'style')
8282
)
83-
head.append(E.SCRIPT(
84-
src='http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.3/zepto.js',
85-
type='text/javascript',
86-
))
87-
head.extend(
88-
E.SCRIPT(
89-
file_contents(js + '.js'),
90-
type='text/javascript',
91-
)
92-
for js in (
93-
'extlib/prefixfree-1.0.4.min',
94-
'script'
95-
)
96-
)
9783
return head
9884

9985
def raw_code(self):
@@ -106,12 +92,12 @@ def code(self):
10692
"""generate the contents of the #code section"""
10793
# Get ready to use Pygments:
10894
formatter = CodeHtmlFormatter(
109-
style='default',
110-
cssclass='source',
111-
linenostart=self.data['function']['lines'][0],
95+
style='default',
96+
cssclass='source',
97+
linenostart=self.data['function']['lines'][0],
11298
)
11399

114-
#<link rel="stylesheet", href="pygments_c.css", type="text/css">
100+
# <link rel="stylesheet", href="pygments_c.css", type="text/css">
115101
open('pygments_c.css', 'w').write(formatter.get_style_defs())
116102

117103
# Use pygments to convert it all to HTML:
@@ -127,7 +113,6 @@ def code(self):
127113

128114
return code
129115

130-
131116
def header(self):
132117
"""Make the header bar of the webpage"""
133118

@@ -136,40 +121,35 @@ def header(self):
136121
E.DIV(
137122
E.ATTR(id='title'),
138123
E.H1(
139-
'GCC Python Plugin',
124+
E.A(
125+
'GCC Python Plugin',
126+
href='http://gcc-python-plugin.readthedocs.org/',
127+
),
140128
),
141129
E.DIV(
142-
E.ATTR(id='filename'),
130+
E.ATTR(id='info'),
143131
E.SPAN(
144132
E.CLASS('label'),
145133
'Filename: ',
146134
),
147135
self.data['filename'],
148-
),
149-
),
150-
E.E.nav(
151-
E.ATTR(id='nav'),
152-
E.DIV(
153-
E.ATTR(id='function'),
154-
E.H3('Function'),
136+
E.SPAN(
137+
E.CLASS('label'),
138+
'Function: ',
139+
),
155140
self.data['function']['name'],
156141
),
157142
E.DIV(
158143
E.ATTR(id='report-pagination'),
159-
E.H3('Report'),
144+
E.SPAN(
145+
E.CLASS('label'),
146+
'Report: ',
147+
),
160148
*(
161149
E.A(str(i + 1), href="#state{0}".format(i + 1))
162150
for i in range(len(self.data['reports']))
163151
)
164152
),
165-
E.DIV(
166-
E.ATTR(id='bug-toggle'),
167-
E.IMG(
168-
src=data_uri('image/png', 'images/bug.png'),
169-
),
170-
E.H3('Bug'),
171-
' [count]',
172-
),
173153
E.DIV(
174154
E.ATTR(id='prev'),
175155
E.IMG(
@@ -183,7 +163,26 @@ def header(self):
183163
),
184164
),
185165
),
186-
)
166+
)
167+
168+
@staticmethod
169+
def footer():
170+
"""put non-essential javascript in the footer"""
171+
return E.E.footer(
172+
# zepto is the one resource we don't embed.
173+
# It's (relatively) big, and non-essential.
174+
E.SCRIPT(
175+
src=(
176+
'http://cdnjs.cloudflare.com'
177+
'/ajax/libs/zepto/1.1.3/zepto.js'
178+
),
179+
type='text/javascript',
180+
),
181+
E.SCRIPT(
182+
file_contents('script.js'),
183+
type='text/javascript',
184+
),
185+
)
187186

188187
def states(self):
189188
"""Return an ordered-list of states, for each report."""
@@ -213,7 +212,7 @@ def states(self):
213212

214213
for note in report['notes']:
215214
line = note['location'][0]['line']
216-
note = E.P({'class':'note'}, note['message'])
215+
note = E.P({'class': 'note'}, note['message'])
217216

218217
# Put this note on the last matching state, if possible
219218
for ann in reversed(tuple(annotations)):
@@ -223,13 +222,11 @@ def states(self):
223222
break
224223
elif line > annline:
225224
ann.addnext(
226-
E.LI({'data-line': str(line)}, note)
225+
E.LI({'data-line': str(line)}, note)
227226
)
228227
break
229228
else:
230-
annotations.insert(0,
231-
E.LI({'data-line': str(line)}, note)
232-
)
229+
annotations.insert(0, E.LI({'data-line': str(line)}, note))
233230

234231
yield annotations, report['message']
235232

@@ -240,38 +237,44 @@ def body(self):
240237

241238
for i, (state_html, state_problem) in enumerate(self.states(), 1):
242239
reports.append(
243-
E.LI(
244-
E.ATTR(id="state{0}".format(i)),
240+
E.LI(
241+
E.ATTR(id="state{0}".format(i)),
242+
E.E.header(
243+
E.DIV(
244+
E.CLASS('error'),
245+
state_problem,
246+
),
247+
E.DIV(
248+
E.CLASS('report-count'),
249+
E.H3('Report'),
250+
str(i),
251+
),
252+
),
253+
E.DIV(
254+
E.CLASS('body'),
245255
E.DIV(
246256
E.CLASS('source'),
247-
E.E.header(
248-
E.DIV(
249-
E.CLASS('error'),
250-
state_problem,
251-
),
252-
E.DIV(
253-
E.CLASS('report-count'),
254-
E.H3('Report'),
255-
str(i),
256-
),
257-
),
258257
deepcopy(code),
259258
),
260259
state_html,
261260
),
261+
),
262262
)
263263

264264
return E.BODY(
265265
self.header(),
266266
reports,
267+
self.footer(),
267268
)
268269

270+
269271
def data_uri(mimetype, filename):
270272
"""represent a file as a data uri"""
271273
data = open(join(HERE, filename), 'rb').read()
272274
data = data.encode('base64').replace('\n', '')
273275
return 'data:%s;base64,%s' % (mimetype, data)
274276

277+
275278
def file_contents(filename):
276279
"""Add a leading newline to make the first line show up in the right spot.
277280
"""
@@ -283,7 +286,7 @@ class CodeHtmlFormatter(HtmlFormatter):
283286

284287
def wrap(self, source, outfile):
285288
yield 0, '<table data-first-line="%s">' % (
286-
self.linenostart,
289+
self.linenostart,
287290
)
288291
for i, line in source:
289292
if i == 1:
@@ -295,6 +298,7 @@ def wrap(self, source, outfile):
295298
yield i, line
296299
yield 0, '</table>'
297300

301+
298302
def main(argv):
299303
"""our entry point"""
300304
if len(argv) < 3:

libcpychecker_html/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ $(function() {
7979
$.each(source_flow, function(idx, flow) {
8080
// Lines mentioned in the flow get dots...
8181
if (flow.length && flow[0].lineno == lineno) {
82-
var $new_cell = $('<td>', { "class": "flow-line" }).html('&#x200b;');
83-
$new_cell.append($('<span>', { "class": "flow-dot" }));
82+
var $new_cell = $('<td>', { "class": "flow-line" });
83+
$new_cell.append($('<span>', { "class": "flow-dot" }).html('&#x200b;'));
8484
$paths = $paths.add($new_cell);
8585
$selectables = $selectables.add($new_cell).add(flow[0].$state);
8686
started[idx] = true;

0 commit comments

Comments
 (0)