-
Notifications
You must be signed in to change notification settings - Fork 3
/
ipatope.py
executable file
·51 lines (36 loc) · 1.47 KB
/
ipatope.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
#!/usr/bin/env python3
from jinja2 import Environment, FileSystemLoader, BaseLoader, DebugUndefined
from pathlib import Path
import yaml
DATA = Path('./data')
jinja_env = Environment(loader=FileSystemLoader('templates'),
# extensions=['jinja2_markdown.MarkdownExtension'],
undefined=DebugUndefined)
class AttrObject:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
with (DATA / 'phonemes.yaml').open('r') as fp:
phonemes = [AttrObject(**ph)
for ph in yaml.load(fp, Loader=yaml.Loader)]
with (DATA / 'filters.yaml').open('r') as fp:
fgrps = {grp: [AttrObject(**fil) for fil in fils]
for grp, fils in yaml.load(fp, Loader=yaml.Loader).items()}
with (DATA / 'sorters.yaml').open('r') as fp:
sorters = [AttrObject(**sor)
for sor in yaml.load(fp, Loader=yaml.Loader)]
data = dict(
phonemes=phonemes,
filtergroups=fgrps,
sorters=sorters,
)
print('INFO', 'writing rendered files to public/')
template = jinja_env.get_template('phonemes.template.html')
with Path('public/index.html').open('w') as out:
out.write(template.render(**data))
code = jinja_env.get_template('ipatope.template.js')
with Path('public/ipatope.js').open('w') as out:
out.write(code.render(**data))
css = jinja_env.get_template('ipatope.template.css')
with Path('public/ipatope.css').open('w') as out:
out.write(css.render(**data))