Skip to content

Commit 2aa9e22

Browse files
committed
Add dark mode
1 parent 3cc63eb commit 2aa9e22

8 files changed

Lines changed: 286 additions & 119 deletions

File tree

lispy.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
'download.html',
2121
'chapter1_introduction.html', 'chapter2_installation.html', 'chapter3_basics.html',
2222
'chapter4_interactive_prompt.html', 'chapter5_languages.html', 'chapter6_parsing.html',
23-
'chapter7_evaluation.html', 'chapter8_error_handling.html', 'chapter9_s_expressions.html',
24-
'chapter10_q_expressions.html', 'chapter11_variables.html', 'chapter12_functions.html',
23+
'chapter7_evaluation.html', 'chapter8_error_handling.html', 'chapter9_s_expressions.html',
24+
'chapter10_q_expressions.html', 'chapter11_variables.html', 'chapter12_functions.html',
2525
'chapter13_conditionals.html', 'chapter14_strings.html', 'chapter15_standard_library.html',
2626
'chapter16_bonus_projects.html',
27-
27+
2828
'appendix_a_hand_rolled_parser.html',
2929
]
3030

@@ -37,7 +37,7 @@
3737
'Q-Expressions • Chapter 10', 'Variables • Chapter 11', 'Functions • Chapter 12',
3838
'Conditionals • Chapter 13', 'Strings • Chapter 14', 'Standard Library • Chapter 15',
3939
'Bonus Projects • Chapter 16',
40-
40+
4141
'Hand Rolled Parser • Appendix A'
4242
]
4343

@@ -61,14 +61,14 @@
6161
<link href="static/css/bootstrap.css" rel="stylesheet">
6262
<link href="static/css/code.css" rel="stylesheet">
6363
<link rel="icon" type="image/png" href="/static/img/favicon.png" />
64-
64+
6565
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
6666
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
6767
<!--[if lt IE 9]>
6868
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
6969
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
7070
<![endif]-->
71-
71+
7272
<script>
7373
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
7474
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -86,18 +86,18 @@
8686
</head>
8787
<body style="background: url(static/img/halftone.png); margin:0px; padding:0px;">
8888
<div style="background: url(static/img/tiletop.png) repeat-x; height:25px;">
89-
89+
9090
<div class='container' style='max-width:750px; padding-top:10px;'>
9191
<div class='row'>
9292
<div class='col-xs-12'>
93-
93+
9494
"""
9595

9696
footer = """
9797
</div>
98-
</div>
98+
</div>
9999
</div>
100-
100+
101101
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
102102
<script src="https://code.jquery.com/jquery.js"></script>
103103
<!-- Include all compiled plugins (below), or include individual files as needed -->
@@ -108,6 +108,8 @@
108108
<script src="static/js/language/generic.js"></script>
109109
<script src="static/js/language/c.js"></script>
110110
<script src="static/js/language/lispy.js"></script>
111+
112+
<script type="module" src="static/js/main.js"></script>
111113
</div>
112114
</body>
113115
</html>
@@ -116,15 +118,15 @@
116118
try:
117119
cache = MemcachedCache(['127.0.0.1:11211'])
118120
except RuntimeError:
119-
121+
120122
class FakeCache:
121123
def get(self, k): return None
122124
def set(self, k, v, **kwargs): return None
123-
125+
124126
cache = FakeCache()
125127

126128
app = Flask(__name__)
127-
129+
128130
handler = logging.FileHandler(os.path.join(os.path.split(__file__)[0], 'error.log'))
129131
handler.setLevel(logging.INFO)
130132
app.logger.addHandler(handler)
@@ -157,85 +159,85 @@ def set(self, k, v, **kwargs): return None
157159
"""
158160

159161
def code_html(codes):
160-
162+
161163
string = ('<div class="panel-group alert alert-warning" id="accordion">\n'
162164
' <div class="panel panel-default">')
163-
165+
164166
for num, code in zip(('One', 'Two', 'Three', 'Four', 'Five'), codes):
165-
167+
166168
string += code_header % (num, code, num)
167-
169+
168170
if code.endswith('.lspy'):
169171
string += '<pre><code data-language=\'lispy\'>'
170172
else:
171173
string += '<pre><code data-language=\'c\'>'
172-
174+
173175
path = os.path.join(os.path.split(__file__)[0], 'src', code)
174-
176+
175177
with open(path, 'r') as f:
176178
contents = f.read()
177179
contents = contents.replace('&', '&amp;')
178180
contents = contents.replace('<', '&lt;')
179181
contents = contents.replace('>', '&gt;')
180182
string += contents
181-
183+
182184
string = string.rstrip() + '</code></pre>'
183185
string += code_footer + '\n\n'
184-
186+
185187
string += '</div>\n </div>'
186188

187189
return string
188-
190+
189191
@app.route('/<page>')
190192
def route_page(page):
191193
page = page + '.html'
192194
if not page in pages: page = '404.html'
193195
path = os.path.join(os.path.split(__file__)[0], page)
194-
196+
195197
index = pages.index(page)
196198
title = titles[index]
197199
codes = sources[index]
198-
200+
199201
contents = cache.get("lispy-" + path)
200202
if contents is None:
201203
contents = open(path, 'r').read()
202204
contents = (header % title) + contents.replace('<references />', code_html(codes)) + footer
203205
cache.set("lispy-" + path, contents, timeout=5*60)
204-
206+
205207
return contents
206-
208+
207209
@app.route('/')
208210
def route_index():
209211
return route_page('splash')
210-
212+
211213
@app.errorhandler(404)
212214
def route_404(e):
213215
return redirect(url_for('route_page', page='404'))
214-
216+
215217
@app.route('/download/<id>/<type>')
216218
@app.route('/download/<id>/BuildYourOwnLisp.<type>')
217219
def route_download(id, type):
218-
220+
219221
keys = os.path.join(os.path.split(__file__)[0], 'purchases')
220-
222+
221223
with open(keys, 'r') as keyfile:
222224
keys = map(lambda x: x.strip(), keyfile.readlines())
223225
keys = map(lambda x: x.split(' '), keys)
224-
keys = set([key[1] for key in keys if
225-
(datetime.datetime.now() -
226-
datetime.datetime.strptime(key[0], '%Y-%m-%d-%H:%M:%S'))
226+
keys = set([key[1] for key in keys if
227+
(datetime.datetime.now() -
228+
datetime.datetime.strptime(key[0], '%Y-%m-%d-%H:%M:%S'))
227229
< datetime.timedelta(days=60)])
228-
230+
229231
if id in keys:
230232
if type == 'epub': return send_file('BuildYourOwnLisp.epub', mimetype='application/epub+zip')
231233
elif type == 'mobi': return send_file('BuildYourOwnLisp.mobi', mimetype='application/x-mobipocket-ebook')
232234
elif type == 'pdf': return send_file('BuildYourOwnLisp.pdf', mimetype='application/pdf')
233235
elif type == 'tar': return send_file('BuildYourOwnLisp.tar.gz', mimetype='application/x-gtar')
234236
else: return redirect(url_for('route_page', page='invalid'))
235-
237+
236238
else: return redirect(url_for('route_page', page='invalid'))
237-
238-
239+
240+
239241
""" Paypal Stuff """
240242

241243
def ordered_storage(f):
@@ -244,7 +246,7 @@ def decorator(*args, **kwargs):
244246
return f(*args, **kwargs)
245247
return decorator
246248
""" Main """
247-
249+
248250
if __name__ == '__main__':
249251
port = int(os.getenv('PORT') or 5000)
250252
app.run(port=port, debug=True)

static/css/bootstrap.min.css

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

static/css/code.css

Lines changed: 51 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,80 @@
1-
2-
pre {
3-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
4-
border: 1px solid #ccc;
5-
word-wrap: break-word;
6-
padding: 6px 10px;
7-
line-height: 19px;
8-
margin-bottom: 20px;
9-
}
10-
1+
/* Code examples & syntax highlighting. Syntax-related CSS classes added via Rainbow.js */
2+
pre,
113
code {
12-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
13-
border: 1px solid #eaeaea;
14-
margin: 0px 2px;
15-
padding: 0px 5px;
16-
font-size: 12px;
17-
}
4+
font-size: 0.9em; /* Looks balanced against surrounding inline text */
185

19-
pre code {
20-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
21-
border: 0px;
22-
padding: 0px;
23-
margin: 0px;
24-
-moz-border-radius: 0px;
25-
-webkit-border-radius: 0px;
26-
border-radius: 0px;
6+
border: 1px solid #eaeaea;
7+
font-family : Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
8+
color : #333;
9+
background : #fcfcfc;
10+
border-radius: 3px;
2711
}
2812

29-
pre, code {
30-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
31-
color: #333;
32-
background: #fcfcfc;
33-
-moz-border-radius: 3px;
34-
-webkit-border-radius: 3px;
35-
border-radius: 3px;
13+
pre {
14+
word-wrap : break-word;
15+
padding : 6px 10px;
16+
line-height : 19px;
17+
margin-bottom: 20px;
3618
}
3719

38-
pre, pre code {
39-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
40-
font-size: 13px;
20+
code {
21+
margin : 0px 2px;
22+
padding : 0px 5px;
4123
}
4224

43-
pre .comment {
44-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
45-
color: #679b7c;
25+
/* Sometimes a <code> inside a <pre> is being informally used to denote command-line content */
26+
pre code, .rainbow {
27+
border : 0px;
28+
padding : 0px;
29+
margin : 0px;
30+
border-radius : 0px;
4631
}
4732

48-
pre .keyword {
49-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
50-
font-weight: bold;
51-
color: #0080c0;
33+
.rainbow .comment {
34+
color : #679b7c;
5235
}
5336

54-
pre .keyword.operator {
55-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
56-
color: #0000a0;
37+
.rainbow .keyword {
38+
font-weight: bold;
39+
color : #0080c0;
5740
}
5841

59-
pre .keyword.builtin {
60-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
61-
color: #800000;
42+
.rainbow .operator {
43+
color : #0000a0;
6244
}
6345

64-
pre .constant.numeric {
65-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
66-
color: #ff8000;
46+
.rainbow .builtin {
47+
color : #800000;
6748
}
6849

69-
pre .constant.string {
70-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
71-
color: #808080;
50+
.rainbow .numeric {
51+
color : #ff8000;
7252
}
7353

74-
pre .constant.character {
75-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
76-
color: #808080;
54+
.rainbow .string {
55+
color : #808080;
7756
}
7857

79-
pre .meta {
80-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
81-
font-weight: bold;
82-
color: #2f2f46;
58+
.rainbow .character {
59+
color : #808080;
8360
}
8461

85-
pre .meta.preprocessor {
86-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
87-
font-weight: normal;
88-
color: #808040;
62+
.rainbow .meta {
63+
font-weight: bold;
64+
color : #2f2f46;
8965
}
9066

91-
pre .support.type {
92-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
93-
font-weight: bold;
94-
color: #800000;
67+
.rainbow .preprocessor {
68+
font-weight: normal;
69+
color : #808040;
9570
}
9671

97-
pre .storage {
98-
font-family: Consolas, 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
99-
font-weight: bold;
100-
color: #ae3f71;
72+
.rainbow .type {
73+
font-weight: bold;
74+
color : #800000;
10175
}
76+
77+
.rainbow .storage {
78+
font-weight: bold;
79+
color : #ae3f71;
80+
}

0 commit comments

Comments
 (0)