forked from slash-lang/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.sl
81 lines (72 loc) · 2.1 KB
/
index.sl
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
<%
try {
require("highlighter");
has_highlighter = true;
} catch e {
has_highlighter = false;
}
def class_name_to_underscores(name) {
name.split("::").map(\part {
part.replace(%r{(?<=[a-z])([A-Z])}, \match { "_" + match[0] }).lower
}).join("/");
}
def unescape_html(html) {
html.replace("<", "<").replace(">", ">").replace(""", "\"");
}
def highlight_code_segments(markdown) {
return markdown unless has_highlighter;
markdown.replace(%r{<pre><code>((.|\n)*?)</code></pre>}, \md {
# hacky unescaping lol:
if md[1].index("<%") {
"<pre><code>" + md[1].replace(%r{<%((.|\n)*?)%>}, \md {
"<%" + Highlighter.new(unescape_html(md[1])).to_html + "%>"
}) + "</pre></code>";
} else {
"<pre><code>" + Highlighter.new(unescape_html(md[1])).to_html + "</code></pre>";
}
});
}
page = "/home";
if Request.path_info != "" {
if %r{^(/[a-z_]+)+/?$}.match(Request.path_info) {
page = Request.path_info;
} else {
Response.status = 404;
page = "/404";
}
}
markdown_source = File.read("pages" + page + ".md");
title = %r{# (.*)\n}.match(markdown_source)[1];
html = highlight_code_segments(Markdown.compile(markdown_source));
documented_classes = [Comparable, Error, Error::Frame, Object, String, Method, BoundMethod, Class, Nil, False, True, Int];
%>
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link href="/style.css" rel="stylesheet" />
<style>
<%#= Pygments.css %>
</style>
</head>
<body>
<nav>
<div id="logo">
<img src="/logo.png" id="logo">
</div>
<h2>Slash</h2>
<ul>
<li><a href="/">Home</a></li>
</ul>
<h2>Documentation</h2>
<ul>
<% for klass in documented_classes.sort(\(a, b) { a.to_s <=> b.to_s }) { %>
<li><a href="/index.sl/doc/<%= class_name_to_underscores(klass.to_s) %>"><%= klass.to_s %></a></li>
<% } %>
</ul>
</nav>
<section>
<%!! html %>
</section>
</body>
</html>