-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
172 lines (152 loc) · 4.49 KB
/
index.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# -*- coding: UTF-8 -*-
"""
Constructs an index.html for debugging the translation and region information.
"""
from regions import regions as get_regions
from names import names as get_names
from labels import labels as get_labels
regions = get_regions()
names = get_names()
labels = get_labels()
def language_abbr(language):
return """<em><abbr title="%s">%s</abbr>.</em>""" % (
{
"E": "English",
"S": "Sindarin",
"Q": "Quenya",
"N": "Ñoldorin",
}.get(language, language),
language
)
def label_html(language):
key = language["Canonical"], language["Language"], "Tengwar", "General Use"
if key not in labels:
return ""
label = labels[key]
return """
<img class="label" src="http://3rin.gs/labels/%s-%st-thumbnail.png" title="%s in the Tengwar">
""" % (
label["Canonical"],
label["Language"][0].lower(),
label["Canonical"]
)
LANGUAGE = """\
<p class="translation"><em><strong>%s:</strong></em> %s%s %s %s</p> %s
"""
def language_html(language):
return LANGUAGE % (
language["Language"],
("*" if "Constructed" in language else ""),
language["Name"],
(
"<em>(%s)</em>" % language["Meaning"]
if
"Meaning" in language and
not "Construction" in language and
not any(
language["Meaning"].lower() == other["Name"].lower()
for other in names[language["Canonical"]]
)
else ""
),
label_html(language),
(
(
"<ul>%s%s</ul>" % (
(
"<br>".join(
" → ".join(
" ".join(
language_abbr(word)
if
len(word) == 1 and
word.upper() == word and
word.isalpha()
else word
for word in part.split(" ")
)
for part in term.split(" > ")
)
for term in language["Construction"].split("; ")
)
),
(
"<ul><small><em>— %s</em></small></ul>" %
language["Constructed"]
if "Consructed" in language
else ""
)
)
)
if "Construction" in language
else ""
),
)
REGION = """\
<tr>
<td valign="top">
<a href="%(href)s"><img class="thumbnail" src="%(thumbnail)s"></a></p>
</td>
<td valign="top">
%(languages)s
</td>
</tr>
"""
def region_html(name, region):
return REGION % {
"href": region["url"],
"thumbnail": "http://3rin.gs/regions/%s.png" % name,
"languages": "".join(
language_html(language)
for language in names.get(name, [])
)
}
HTML = """\
<html>
<head>
<title>Ennorath</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<style>
body, p, td, th, li, a {
/* http://www.awayback.com/revised-font-stack/ */
font-family: Garamond,Baskerville,"Baskerville Old Face","Hoefler Text","Times New Roman",serif;
font-size: 24px;
}
small {
font-size: 70%%;
}
td {
padding: 1em;
}
a {
color: #0000aa;
}
a:visited {
color: #7777aa;
}
img.thumbnail {
border: solid 1px #cccccc;
height: 200px;
width: 200px;
}
img.label {
height: 100px;
vertical-align: middle;
}
p.translation {
line-height: 100px;
}
</style>
</head>
<body>
<table>
%s
</table>
</body>
</html>
"""
html = HTML % "".join(
region_html(name, region)
for name, region in sorted(regions.items())
)
open('index.html', 'w').write(html.encode("UTF-8"))