1
1
#!/usr/bin/env python
2
2
"""Make our data into HTML!
3
- These reports should be usable as email attachments, so either inline or cdn *everything*.
3
+ These reports should be usable as email attachments, offline.
4
+ This means we need to embed *all* our assets.
5
+
6
+ TODO: #11 optimize the filesize
4
7
"""
5
8
from __future__ import print_function
9
+ from __future__ import unicode_literals
6
10
7
11
# Copyright 2012 Buck Golemon <buck@yelp.com>
8
12
#
35
39
from copy import deepcopy
36
40
from itertools import islice
37
41
42
+
43
+ def open (filename , mode = 'r' ):
44
+ """All files are treated as UTF-8, unless explicitly binary."""
45
+ from io import open
46
+ if 'b' in mode :
47
+ return open (filename , mode )
48
+ else :
49
+ return open (filename , mode , encoding = 'UTF-8' )
50
+
51
+
38
52
class HtmlPage (object ):
39
53
"""Represent one html page."""
40
54
def __init__ (self , codefile , data ):
@@ -57,31 +71,24 @@ def head(self):
57
71
}),
58
72
E .TITLE ('%s -- GCC Python Plugin' % self .data ['filename' ]),
59
73
)
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
- ))
65
74
head .extend (
66
75
E .STYLE (
67
76
file_contents (css + '.css' ),
68
77
media = 'screen' ,
69
78
type = 'text/css'
70
79
)
71
- for css in ('pygments_c' , 'style' )
80
+ for css in ('extlib/reset-20110126' , ' pygments_c' , 'style' )
72
81
)
73
82
head .extend (
74
- E .SCRIPT (src = js )
75
- for js in (
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
83
E .SCRIPT (
82
- file_contents ('script .js' ),
84
+ file_contents (js + ' .js' ),
83
85
type = 'text/javascript' ,
84
86
)
87
+ for js in (
88
+ 'extlib/prefixfree-1.0.4.min' ,
89
+ 'extlib/jquery-1.7.1.min' ,
90
+ 'script'
91
+ )
85
92
)
86
93
return head
87
94
@@ -256,7 +263,8 @@ def body(self):
256
263
)
257
264
258
265
def data_uri (mimetype , filename ):
259
- data = open (join (HERE , filename )).read ().encode ('base64' ).replace ('\n ' , '' )
266
+ "represent a file as a data uri"
267
+ data = open (join (HERE , filename ), 'rb' ).read ().encode ('base64' ).replace ('\n ' , '' )
260
268
return 'data:%s;base64,%s' % (mimetype , data )
261
269
262
270
def file_contents (filename ):
0 commit comments