-
Notifications
You must be signed in to change notification settings - Fork 14
/
templates.py
128 lines (95 loc) · 3.42 KB
/
templates.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import pybars
from html import escape
import markdown
import markdown.extensions.fenced_code
from cache import fetch
gitHub = "https://github.com/"
gitHubRaw = "https://raw.githubusercontent.com"
fenced_code = markdown.extensions.fenced_code.makeExtension()
toHtml = lambda text: markdown.markdown(text, extensions=[fenced_code], output_format="html5")
index = u"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="style.css" media="all" rel="stylesheet">
<link rel="stylesheet" href="packages.css">
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<title>{{title}}</title>
</head>
<body>
<div class="center">
<h1> Packages </h1>
{{#pkglist pkgs}}{{/pkglist}}
</div>
</body>
</html>
"""
package = u"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="style.css" media="all" rel="stylesheet">
<link rel="stylesheet" href="packages.css">
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<title>{{pkg_name}}</title>
</head>
<body>
<div class="center">
<span style="font-size:24px;">{{pkg_name}} - version: {{version}}</span>
<p>for more information visit the package's <a href="https://github.com/{{pkg_name}}/tree/{{version}}">GitHub page</a></p>
<p>Package contains the following modules:
{{#moduleslist modules}}{{/moduleslist}}
{{{gitRM pkg_name}}}
</div">
</body>
</html>
"""
module = u"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="style.css" media="all" rel="stylesheet">
<link rel="stylesheet" href="packages.css">
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<title>{{module_name}}</title>
</head>
<body>
<div class="center">
<div style="padding-top:10px;"> <span style="font-size:24px">{{{package pkg_link}}} / {{module_name}}</span></div>
{{{markdown}}}
</div">
</body>
</html>
"""
def moduleslist(this, options, items):
result = [u'<ul class="modulesList">']
for (name, link) in items:
result.append(u'<li>')
result.append(u'<a name="//apple_ref/cpp/Module/%s" class="dashAnchor"></a>'%name)
result.append(u'<a href="%s">%s</a>'%(link, name))
result.append(u'</li>')
result.append(u'</ul>')
return result
def gitRM(this, name):
readme = fetch("/".join([gitHub, name, "raw/master", "README.md"]), False)
result = toHtml(readme)
return result
def package_helper(this, nameLink):
(name, link) = nameLink
(author, package) = name.split("/")
return '<span> %s / <a href="%s">%s</a></span>'%(author, link, package)
def pkglist(this, options, items):
result = [u'<table>']
for (name, link, summary) in items:
result.append(u'<tr>')
result.append(u'<td class="first"><a href="%s">%s</a></td>'%(link, name))
result.append(u'<td>%s</td>'%escape(summary))
result.append(u'</tr>')
result.append(u'</table>')
return result
indexTemplate = lambda d: pybars.Compiler().compile(index)(d, helpers={"pkglist":pkglist}).encode("utf-8")
pkgTemplate = lambda d: pybars.Compiler().compile(package)(d, helpers={"moduleslist":moduleslist, "gitRM":gitRM}).encode("utf-8")
moduleTemplate = lambda d: pybars.Compiler().compile(module)(d, helpers={"package":package_helper}).encode("utf-8")