|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """Make our data into HTML!""" |
| 3 | +from __future__ import print_function |
3 | 4 |
|
4 | 5 | # Copyright 2012 Buck Golemon <buck@yelp.com> |
5 | 6 | # |
|
17 | 18 | # along with this program. If not, see |
18 | 19 | # <http://www.gnu.org/licenses/>. |
19 | 20 |
|
20 | | -import capi |
| 21 | +from . import capi |
21 | 22 |
|
22 | 23 | from lxml.html import ( |
23 | 24 | tostring, fragment_fromstring as parse, builder as E |
|
29 | 30 |
|
30 | 31 | from copy import deepcopy |
31 | 32 | from itertools import islice |
32 | | -from json import load |
33 | 33 |
|
34 | 34 | class HtmlPage(object): |
35 | 35 | """Represent one html page.""" |
36 | | - def __init__(self, codefile, jsonfile): |
| 36 | + def __init__(self, codefile, data): |
37 | 37 | self.codefile = codefile |
38 | | - self.data = load(jsonfile) |
| 38 | + self.data = data |
39 | 39 |
|
40 | 40 | def __str__(self): |
41 | 41 | html = tostring(self.__html__()) |
42 | 42 | return '<!DOCTYPE html>\n' + html |
43 | 43 |
|
44 | 44 | def __html__(self): |
45 | | - return E.HTML( self.head(), self.body() ) |
| 45 | + return E.HTML(self.head(), self.body()) |
46 | 46 |
|
47 | 47 | def head(self): |
48 | 48 | """The HEAD of the html document""" |
49 | | - head = E.HEAD( |
| 49 | + head = E.HEAD( |
50 | 50 | E.META({ |
51 | 51 | 'http-equiv': 'Content-Type', |
52 | 52 | 'content': 'text/html; charset=utf-8' |
@@ -86,7 +86,7 @@ def code(self): |
86 | 86 | open('pygments_c.css', 'w').write(formatter.get_style_defs()) |
87 | 87 |
|
88 | 88 | # Use pygments to convert it all to HTML: |
89 | | - code = parse(highlight(self.raw_code(), CLexer(), formatter)) |
| 89 | + code = parse(highlight(self.raw_code(), CLexer(), formatter)) |
90 | 90 |
|
91 | 91 | # linkify the python C-API functions |
92 | 92 | for name in code.xpath('//span[@class="n"]'): |
@@ -210,7 +210,7 @@ def states(self): |
210 | 210 | ) |
211 | 211 | break |
212 | 212 | else: |
213 | | - annotations.insert(0, |
| 213 | + annotations.insert(0, |
214 | 214 | E.LI({'data-line': str(line)}, note) |
215 | 215 | ) |
216 | 216 |
|
@@ -271,9 +271,11 @@ def main(argv): |
271 | 271 | """our entry point""" |
272 | 272 | if len(argv) < 3: |
273 | 273 | return "Please provide code and json filenames." |
| 274 | + |
| 275 | + from json import load |
274 | 276 | codefile = open(argv[1]) |
275 | | - jsonfile = open(argv[2]) |
276 | | - print(HtmlPage(codefile, jsonfile)) |
| 277 | + data = load(open(argv[2])) |
| 278 | + print(HtmlPage(codefile, data)) |
277 | 279 |
|
278 | 280 | if __name__ == '__main__': |
279 | 281 | from sys import argv as ARGV |
|
0 commit comments