Skip to content

Commit 293fe92

Browse files
committed
Merge branch 'bukzor-optimize-htmlv2-weight'
2 parents 065ffac + d2fea2b commit 293fe92

16 files changed

+80
-93
lines changed

libcpychecker/refcounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4386,7 +4386,7 @@ def check_refcounts(fun, dump_traces=False, show_traces=False,
43864386
filename_v2 = ('%s.%s-refcount-errors.v2.html'
43874387
% (gcc.get_dump_base_name(), fun.decl.name))
43884388

4389-
from libcpychecker.html.make_html import HtmlPage
4389+
from libcpychecker_html.make_html import HtmlPage
43904390
data = rep.to_json(fun)
43914391
srcfile = open(fun.start.file)
43924392
htmlfile = open(filename_v2, 'w')
File renamed without changes.

libcpychecker_html/extlib/jquery-1.7.1.min.js

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

libcpychecker_html/extlib/reset-20110126.css

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

libcpychecker_html/extlib/reset-20110126.min.css

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libcpychecker_html/extlib/zepto-1.1.3.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libcpychecker_html/images/arrow-180.png

100755100644
-194 Bytes
Loading

libcpychecker_html/images/arrow.png

-48.9 KB
Loading

libcpychecker_html/images/bug--arrow.png

100755100644
-172 Bytes
Loading

libcpychecker_html/images/bug.png

100755100644
-209 Bytes
Loading
-174 Bytes
Loading

libcpychecker_html/images/footer-bg.png

100755100644
-56 Bytes
Loading

libcpychecker_html/images/header-bg.png

100755100644
-58 Bytes
Loading

libcpychecker_html/make_html.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/usr/bin/env python
2-
"""Make our data into HTML!"""
2+
"""Make our data into HTML!
3+
These reports should be usable as email attachments, offline.
4+
This means we need to embed *all* our assets.
5+
6+
We make an exception for zepto; it's (relatively) big, and the behaviors
7+
it adds are non-essential to reading the report.
8+
"""
39
from __future__ import print_function
10+
from __future__ import unicode_literals
411

512
# Copyright 2012 Buck Golemon <buck@yelp.com>
613
#
@@ -17,6 +24,8 @@
1724
# You should have received a copy of the GNU General Public License
1825
# along with this program. If not, see
1926
# <http://www.gnu.org/licenses/>.
27+
from os.path import realpath, dirname, join
28+
HERE = dirname(realpath(__file__))
2029

2130
from . import capi
2231

@@ -31,6 +40,16 @@
3140
from copy import deepcopy
3241
from itertools import islice
3342

43+
44+
def open(filename, mode='r'):
45+
"""All files are treated as UTF-8, unless explicitly binary."""
46+
from io import open
47+
if 'b' in mode:
48+
return open(filename, mode)
49+
else:
50+
return open(filename, mode, encoding='UTF-8')
51+
52+
3453
class HtmlPage(object):
3554
"""Represent one html page."""
3655
def __init__(self, codefile, data):
@@ -54,14 +73,24 @@ def head(self):
5473
E.TITLE('%s -- GCC Python Plugin' % self.data['filename']),
5574
)
5675
head.extend(
57-
E.LINK(rel='stylesheet', href=css + '.css', type='text/css')
58-
for css in ('extlib/reset-20110126', 'pygments_c', 'style')
76+
E.STYLE(
77+
file_contents(css + '.css'),
78+
media='screen',
79+
type='text/css'
80+
)
81+
for css in ('extlib/reset-20110126.min', 'pygments_c', 'style')
5982
)
83+
head.append(E.SCRIPT(
84+
src='http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.3/zepto.js',
85+
type='text/javascript',
86+
))
6087
head.extend(
61-
E.SCRIPT(src=js + '.js')
88+
E.SCRIPT(
89+
file_contents(js + '.js'),
90+
type='text/javascript',
91+
)
6292
for js in (
6393
'extlib/prefixfree-1.0.4.min',
64-
'extlib/jquery-1.7.1.min',
6594
'script'
6695
)
6796
)
@@ -136,38 +165,26 @@ def header(self):
136165
E.DIV(
137166
E.ATTR(id='bug-toggle'),
138167
E.IMG(
139-
src='images/bug.png',
168+
src=data_uri('image/png', 'images/bug.png'),
140169
),
141170
E.H3('Bug'),
142171
' [count]',
143172
),
144173
E.DIV(
145174
E.ATTR(id='prev'),
146175
E.IMG(
147-
src='images/arrow-180.png',
176+
src=data_uri('image/png', 'images/arrow-180.png'),
148177
),
149178
),
150179
E.DIV(
151180
E.ATTR(id='next'),
152181
E.IMG(
153-
src='images/arrow.png',
182+
src=data_uri('image/png', 'images/arrow.png'),
154183
),
155184
),
156185
),
157186
)
158187

159-
@staticmethod
160-
def footer():
161-
"""make the footer"""
162-
return E.E.footer(
163-
E.ATTR(id='footer'),
164-
E.P(' &nbsp;|&nbsp; '.join((
165-
'Hackathon 7.0',
166-
'Buck G, Alex M, Jason M',
167-
'Yelp HQ 2012',
168-
)))
169-
)
170-
171188
def states(self):
172189
"""Return an ordered-list of states, for each report."""
173190
for report in self.data['reports']:
@@ -247,9 +264,20 @@ def body(self):
247264
return E.BODY(
248265
self.header(),
249266
reports,
250-
self.footer(),
251267
)
252268

269+
def data_uri(mimetype, filename):
270+
"""represent a file as a data uri"""
271+
data = open(join(HERE, filename), 'rb').read()
272+
data = data.encode('base64').replace('\n', '')
273+
return 'data:%s;base64,%s' % (mimetype, data)
274+
275+
def file_contents(filename):
276+
"""Add a leading newline to make the first line show up in the right spot.
277+
"""
278+
return '\n' + open(join(HERE, filename)).read()
279+
280+
253281
class CodeHtmlFormatter(HtmlFormatter):
254282
"""Format our HTML!"""
255283

libcpychecker_html/script.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ $(function() {
8989
// state commentary, highlight the dot and the comment and
9090
// the row itself
9191
var $group = $row.add(flow[0].$state).add($new_cell);
92-
$new_cell.add(flow[0].$state).hover(
93-
function() { $group.addClass('selected'); },
94-
function() { $group.removeClass('selected'); }
95-
);
92+
$new_cell.add(flow[0].$state).on({
93+
mouseenter: function() { $group.addClass('selected'); },
94+
mouseleave: function() { $group.removeClass('selected'); }
95+
});
9696

9797
flow.shift();
9898
}
@@ -117,10 +117,10 @@ $(function() {
117117
// with that line
118118
if ($selectables.length) {
119119
$selectables = $selectables.add($row);
120-
$row.find('td:last-child').hover(
121-
function() { $selectables.addClass('selected') },
122-
function() { $selectables.removeClass('selected') }
123-
);
120+
$row.find('td:last-child').on({
121+
mouseenter: function() { $selectables.addClass('selected') },
122+
mouseleave: function() { $selectables.removeClass('selected') }
123+
});
124124
}
125125
});
126126
});

libcpychecker_html/style.css

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,7 @@ img {
5656
#reports {
5757
box-flex: 1;
5858
overflow-y: auto;
59-
}
60-
#footer {
61-
background: hsl(0, 0%, 30%);
62-
box-shadow: inset 0 3px 3px -3px black;
63-
color: white;
64-
padding: 0.83em;
65-
text-shadow: 0px 1px 0px black;
66-
background-color: #09f;
59+
overflow-x: hidden;
6760
}
6861

6962

@@ -72,7 +65,7 @@ img {
7265
display: box;
7366
box-orient: horizontal;
7467
width: 100%;
75-
padding: 1em;
68+
padding: 0.5em;
7669
box-sizing: border-box;
7770
color: white;
7871
}
@@ -190,6 +183,8 @@ img {
190183
line-height: 1.33;
191184
min-width: 40em;
192185
box-flex: 3;
186+
overflow-x: auto;
187+
border-right: 1px solid hsl(0, 0%, 70%);
193188
}
194189
.source > header {
195190
display: box;
@@ -285,9 +280,10 @@ img {
285280
text-align: right;
286281
user-select: none;
287282
color: hsl(0, 0%, 60%);
283+
vertical-align: middle;
288284
}
289285
.source .code {
290-
white-space: pre-wrap;
286+
white-space: pre;
291287
}
292288

293289

@@ -394,7 +390,15 @@ td.selected .flow-dot {
394390
min-width: 200px;
395391
}
396392

393+
.note {
394+
font-weight: bolder;
395+
}
397396
.note:first-of-type::before {
398-
content: url('images/exclamation.png');
397+
/* content: url('images/exclamation.png');
398+
* to regenerate:
399+
* from libcpychecker_html.make_html import data_uri
400+
* data_uri('image/png', 'images/exclamation.png')
401+
*/
402+
content: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAjBJREFUeNqkk0trE1EUx8/cO49OfGTSRNJMYsA0aVonoYh13YW71uJCKFQhKqibfgFLwYULsR/AhY+VG1d+C124kJiFIGipmoIZNUXtZDKTycz1njGpaRNU8MJv7txzzv/c5xEYY/A/TRQEAW5c5KwM+aKcR73/a5zvg84HT371wv07Apwuj0x+PZW/vArA4NO7x/f4+OGoIHLKAAiC/fBdHadSbCGZPTeTzC7OUElbQNvBOISMMnIqeqFSYs57mTkfZD1/qYS2f0rAZ5pVDmXnY/FSbn3jM6xvfAEtfjKnRDLz6BtK4PPPADi+ms6vGK71lti2DUintUVSJ84b6OvF7GlI4PNMPVgAZ49oxpyqRnXf+wGWZYX4ngWRiKYfPpqfw5hBjej7eweqCkSo6JOLhmd/hI7vQLVaBdM0YXt1FgK2CeJ40fCbmxUWsGc8vh3egtcFQPhyLsQnzpQJcbVmuw5mawtqtRo0Gg3wJQeY7ALIrqZEM2WM7esIPkROAgR5OZEpTTV3X4IXNEGiLnw1b4fItBNCBQuiqeQUA7qMGtSSLt8C38aVRLo47QVvVJFYoFAnJJG8FdIfI6rSVWMTx6ZRg1rS7UKeSspSMj2Wk+AbjPGZ+vTboA1JZbQcEcUl1Iq2zdZyxURBpruUMTzR38Vl79wM+9bO0/3vlwLVs+OF16/MNdFug/vi+Xadm+vDL/3uHyuR16Er4E3gKvEaOTLa/1LBuEQPF8hxfgowAINnMqTBUH7hAAAAAElFTkSuQmCC');
399403
padding: 5px;
400404
}

0 commit comments

Comments
 (0)