Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions libcpychecker_html/extlib/prefixfree-1.0.4.min.js

This file was deleted.

128 changes: 66 additions & 62 deletions libcpychecker_html/make_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from . import capi

from lxml.html import (
tostring, fragment_fromstring as parse, builder as E
tostring, fragment_fromstring as parse, builder as E
)

from pygments import highlight
Expand All @@ -41,13 +41,13 @@
from itertools import islice


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


class HtmlPage(object):
Expand Down Expand Up @@ -80,20 +80,6 @@ def head(self):
)
for css in ('extlib/reset-20110126.min', 'pygments_c', 'style')
)
head.append(E.SCRIPT(
src='http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.3/zepto.js',
type='text/javascript',
))
head.extend(
E.SCRIPT(
file_contents(js + '.js'),
type='text/javascript',
)
for js in (
'extlib/prefixfree-1.0.4.min',
'script'
)
)
return head

def raw_code(self):
Expand All @@ -106,12 +92,12 @@ def code(self):
"""generate the contents of the #code section"""
# Get ready to use Pygments:
formatter = CodeHtmlFormatter(
style='default',
cssclass='source',
linenostart=self.data['function']['lines'][0],
style='default',
cssclass='source',
linenostart=self.data['function']['lines'][0],
)

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

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

return code


def header(self):
"""Make the header bar of the webpage"""

Expand All @@ -136,40 +121,35 @@ def header(self):
E.DIV(
E.ATTR(id='title'),
E.H1(
'GCC Python Plugin',
E.A(
'GCC Python Plugin',
href='http://gcc-python-plugin.readthedocs.org/',
),
),
E.DIV(
E.ATTR(id='filename'),
E.ATTR(id='info'),
E.SPAN(
E.CLASS('label'),
'Filename: ',
),
self.data['filename'],
),
),
E.E.nav(
E.ATTR(id='nav'),
E.DIV(
E.ATTR(id='function'),
E.H3('Function'),
E.SPAN(
E.CLASS('label'),
'Function: ',
),
self.data['function']['name'],
),
E.DIV(
E.ATTR(id='report-pagination'),
E.H3('Report'),
E.SPAN(
E.CLASS('label'),
'Report: ',
),
*(
E.A(str(i + 1), href="#state{0}".format(i + 1))
for i in range(len(self.data['reports']))
)
),
E.DIV(
E.ATTR(id='bug-toggle'),
E.IMG(
src=data_uri('image/png', 'images/bug.png'),
),
E.H3('Bug'),
' [count]',
),
E.DIV(
E.ATTR(id='prev'),
E.IMG(
Expand All @@ -183,7 +163,26 @@ def header(self):
),
),
),
)
)

@staticmethod
def footer():
"""put non-essential javascript in the footer"""
return E.E.footer(
# zepto is the one resource we don't embed.
# It's (relatively) big, and non-essential.
E.SCRIPT(
src=(
'http://cdnjs.cloudflare.com'
'/ajax/libs/zepto/1.1.3/zepto.js'
),
type='text/javascript',
),
E.SCRIPT(
file_contents('script.js'),
type='text/javascript',
),
)

def states(self):
"""Return an ordered-list of states, for each report."""
Expand Down Expand Up @@ -213,7 +212,7 @@ def states(self):

for note in report['notes']:
line = note['location'][0]['line']
note = E.P({'class':'note'}, note['message'])
note = E.P({'class': 'note'}, note['message'])

# Put this note on the last matching state, if possible
for ann in reversed(tuple(annotations)):
Expand All @@ -223,13 +222,11 @@ def states(self):
break
elif line > annline:
ann.addnext(
E.LI({'data-line': str(line)}, note)
E.LI({'data-line': str(line)}, note)
)
break
else:
annotations.insert(0,
E.LI({'data-line': str(line)}, note)
)
annotations.insert(0, E.LI({'data-line': str(line)}, note))

yield annotations, report['message']

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

for i, (state_html, state_problem) in enumerate(self.states(), 1):
reports.append(
E.LI(
E.ATTR(id="state{0}".format(i)),
E.LI(
E.ATTR(id="state{0}".format(i)),
E.E.header(
E.DIV(
E.CLASS('error'),
state_problem,
),
E.DIV(
E.CLASS('report-count'),
E.H3('Report'),
str(i),
),
),
E.DIV(
E.CLASS('body'),
E.DIV(
E.CLASS('source'),
E.E.header(
E.DIV(
E.CLASS('error'),
state_problem,
),
E.DIV(
E.CLASS('report-count'),
E.H3('Report'),
str(i),
),
),
deepcopy(code),
),
state_html,
),
),
)

return E.BODY(
self.header(),
reports,
self.footer(),
)


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


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

def wrap(self, source, outfile):
yield 0, '<table data-first-line="%s">' % (
self.linenostart,
self.linenostart,
)
for i, line in source:
if i == 1:
Expand All @@ -295,6 +298,7 @@ def wrap(self, source, outfile):
yield i, line
yield 0, '</table>'


def main(argv):
"""our entry point"""
if len(argv) < 3:
Expand Down
4 changes: 2 additions & 2 deletions libcpychecker_html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ $(function() {
$.each(source_flow, function(idx, flow) {
// Lines mentioned in the flow get dots...
if (flow.length && flow[0].lineno == lineno) {
var $new_cell = $('<td>', { "class": "flow-line" }).html('&#x200b;');
$new_cell.append($('<span>', { "class": "flow-dot" }));
var $new_cell = $('<td>', { "class": "flow-line" });
$new_cell.append($('<span>', { "class": "flow-dot" }).html('&#x200b;'));
$paths = $paths.add($new_cell);
$selectables = $selectables.add($new_cell).add(flow[0].$state);
started[idx] = true;
Expand Down
Loading