|
1 | 1 | #!/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, so either inline or cdn *everything*. |
| 4 | +""" |
3 | 5 | from __future__ import print_function |
4 | 6 |
|
5 | 7 | # Copyright 2012 Buck Golemon <buck@yelp.com> |
|
17 | 19 | # You should have received a copy of the GNU General Public License |
18 | 20 | # along with this program. If not, see |
19 | 21 | # <http://www.gnu.org/licenses/>. |
| 22 | +from os.path import realpath, dirname, join |
| 23 | +HERE = dirname(realpath(__file__)) |
20 | 24 |
|
21 | 25 | from . import capi |
22 | 26 |
|
@@ -53,16 +57,30 @@ def head(self): |
53 | 57 | }), |
54 | 58 | E.TITLE('%s -- GCC Python Plugin' % self.data['filename']), |
55 | 59 | ) |
| 60 | + head.append(E.LINK( |
| 61 | + rel='stylesheet', |
| 62 | + href='http://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css', |
| 63 | + type='text/css' |
| 64 | + )) |
56 | 65 | head.extend( |
57 | | - E.LINK(rel='stylesheet', href=css + '.css', type='text/css') |
58 | | - for css in ('extlib/reset-20110126', 'pygments_c', 'style') |
| 66 | + E.STYLE( |
| 67 | + file_contents(css + '.css'), |
| 68 | + media='screen', |
| 69 | + type='text/css' |
| 70 | + ) |
| 71 | + for css in ('pygments_c', 'style') |
59 | 72 | ) |
60 | 73 | head.extend( |
61 | | - E.SCRIPT(src=js + '.js') |
| 74 | + E.SCRIPT(src=js) |
62 | 75 | for js in ( |
63 | | - 'extlib/prefixfree-1.0.4.min', |
64 | | - 'extlib/jquery-1.7.1.min', |
65 | | - 'script' |
| 76 | + 'http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js', |
| 77 | + 'http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js', |
| 78 | + ) |
| 79 | + ) |
| 80 | + head.append( |
| 81 | + E.SCRIPT( |
| 82 | + file_contents('script.js'), |
| 83 | + type='text/javascript', |
66 | 84 | ) |
67 | 85 | ) |
68 | 86 | return head |
@@ -136,38 +154,26 @@ def header(self): |
136 | 154 | E.DIV( |
137 | 155 | E.ATTR(id='bug-toggle'), |
138 | 156 | E.IMG( |
139 | | - src='images/bug.png', |
| 157 | + src=data_uri('image/png', 'images/bug.png'), |
140 | 158 | ), |
141 | 159 | E.H3('Bug'), |
142 | 160 | ' [count]', |
143 | 161 | ), |
144 | 162 | E.DIV( |
145 | 163 | E.ATTR(id='prev'), |
146 | 164 | E.IMG( |
147 | | - src='images/arrow-180.png', |
| 165 | + src=data_uri('image/png', 'images/arrow-180.png'), |
148 | 166 | ), |
149 | 167 | ), |
150 | 168 | E.DIV( |
151 | 169 | E.ATTR(id='next'), |
152 | 170 | E.IMG( |
153 | | - src='images/arrow.png', |
| 171 | + src=data_uri('image/png', 'images/arrow.png'), |
154 | 172 | ), |
155 | 173 | ), |
156 | 174 | ), |
157 | 175 | ) |
158 | 176 |
|
159 | | - @staticmethod |
160 | | - def footer(): |
161 | | - """make the footer""" |
162 | | - return E.E.footer( |
163 | | - E.ATTR(id='footer'), |
164 | | - E.P(' | '.join(( |
165 | | - 'Hackathon 7.0', |
166 | | - 'Buck G, Alex M, Jason M', |
167 | | - 'Yelp HQ 2012', |
168 | | - ))) |
169 | | - ) |
170 | | - |
171 | 177 | def states(self): |
172 | 178 | """Return an ordered-list of states, for each report.""" |
173 | 179 | for report in self.data['reports']: |
@@ -247,9 +253,17 @@ def body(self): |
247 | 253 | return E.BODY( |
248 | 254 | self.header(), |
249 | 255 | reports, |
250 | | - self.footer(), |
251 | 256 | ) |
252 | 257 |
|
| 258 | +def data_uri(mimetype, filename): |
| 259 | + data = open(join(HERE, filename)).read().encode('base64').replace('\n', '') |
| 260 | + return 'data:%s;base64,%s' % (mimetype, data) |
| 261 | + |
| 262 | +def file_contents(filename): |
| 263 | + # The leading newline makes the first line show up in the right spot. |
| 264 | + return '\n' + open(join(HERE, filename)).read() |
| 265 | + |
| 266 | + |
253 | 267 | class CodeHtmlFormatter(HtmlFormatter): |
254 | 268 | """Format our HTML!""" |
255 | 269 |
|
|
0 commit comments