forked from simulationcraft/simc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
css-to-cpp.py
executable file
·101 lines (86 loc) · 3.01 KB
/
css-to-cpp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
import re
import string
# Read current styles.css file and write slimmed-down version for inclusion
# in report\sc_report.cpp
OUTFILE = open('cpp-styles.txt', 'w')
OUTFILE.write(' // Styles\n')
OUTFILE.write(' // If file is being hosted on simulationcraft.org, link to the local\n')
OUTFILE.write(' // stylesheet; otherwise, embed the styles.\n')
OUTFILE.write(' if ( sim -> hosted_html )\n')
OUTFILE.write(' {\n')
OUTFILE.write(' os << "\\t\\t<style type=\\"text/css\\" media=\\"screen\\">\\n"\n')
OUTFILE.write(' << "\\t\\t\\t@import url(\'http://www.simulationcraft.org/css/styles.css\');\\n"\n')
OUTFILE.write(' << "\\t\\t</style>\\n"\n')
OUTFILE.write(' << "\\t\\t<style type=\\"text/css\\" media=\\"print\\">\\n"\n')
OUTFILE.write(' << "\\t\\t\t@import url(\'http://www.simulationcraft.org/css/styles-print.css\');\\n"\n')
OUTFILE.write(' << "\\t\\t</style>\\n";\n')
OUTFILE.write(' }\n')
OUTFILE.write(' else if ( sim -> print_styles )\n')
OUTFILE.write(' {\n')
OUTFILE.write(' os << "\\t\\t<style type=\\"text/css\\" media=\\"all\\">\\n"\n')
INFILE = open('../../simulationcraft_html/css/styles-print.css', 'r')
lines = []
comment = False
for line in INFILE.readlines():
line = string.strip(line)
if not line:
continue
if line[0:2] == '/*':
comment = True
continue
elif line[0:2] == '*/':
comment = False
continue
if comment:
continue
line = re.sub('"', '\\"', line)
lines.append(line)
line_count = len(lines)
new_line = ' << "\\t\\t\\t'
for line in lines:
if line == '}':
new_line = '{0} }}\\n"'.format(new_line)
new_line = '{0}\n'.format(new_line)
OUTFILE.write(new_line)
new_line = ' << "\\t\\t\\t'
continue
new_line = '{0}{1}'.format(new_line, line)
OUTFILE.write(' << "\\t\\t</style>\\n";\n')
INFILE.close()
OUTFILE.write(' }\n')
OUTFILE.write(' else\n')
OUTFILE.write(' {\n')
OUTFILE.write(' os << "\\t\\t<style type=\\"text/css\\" media=\\"all\\">\\n"\n')
INFILE = open('../../simulationcraft_html/css/styles.css', 'r')
lines = []
comment = False
for line in INFILE.readlines():
line = string.strip(line)
if not line:
continue
if line[0:2] == '/*':
comment = True
continue
elif line[0:2] == '*/':
comment = False
continue
elif re.search('images\/hosted_html\/bg\.jpg', line):
line = re.sub(' url\(\.\.\/images\/hosted_html\/bg\.jpg\) \-100px 5px', '', line)
if comment:
continue
line = re.sub('"', '\\"', line)
lines.append(line)
line_count = len(lines)
new_line = ' << "\\t\\t\\t'
for line in lines:
if line == '}':
new_line = '{0} }}\\n"'.format(new_line)
new_line = '{0}\n'.format(new_line)
OUTFILE.write(new_line)
new_line = ' << "\\t\\t\\t'
continue
new_line = '{0}{1}'.format(new_line, line)
OUTFILE.write(' << "\\t\\t</style>\\n";\n')
OUTFILE.write(' }\n')
INFILE.close()