forked from pre-commit/pre-commit.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_templates.py
43 lines (31 loc) · 1022 Bytes
/
make_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
from __future__ import absolute_import
from __future__ import unicode_literals
import collections
import json
import os.path
import mako.lookup
template_lookup = mako.lookup.TemplateLookup(
directories=['.'],
default_filters=['html_escape'],
imports=['from mako.filters import html_escape'],
)
ALL_TEMPLATES = [
filename for filename in os.listdir('.')
if filename.endswith('.mako') and filename != 'base.mako'
]
def get_env():
all_hooks = json.loads(
open('all-hooks.json').read(),
object_pairs_hook=collections.OrderedDict,
)
return {'all_hooks': all_hooks}
def main():
env = get_env()
for template in ALL_TEMPLATES:
template_name, _ = os.path.splitext(template)
env['template_name'] = template_name
with open('{}.html'.format(template_name), 'w') as html_file:
template_obj = template_lookup.get_template(template)
html_file.write(template_obj.render(**env))
if __name__ == '__main__':
exit(main())