forked from pre-commit/pre-commit.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_templates.py
50 lines (39 loc) · 1.22 KB
/
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
44
45
46
47
48
49
50
import collections
import json
import os.path
from typing import Any
from typing import Dict
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() -> Dict[str, Any]:
all_hooks = json.loads(
open('all-hooks.json').read(),
object_pairs_hook=collections.OrderedDict,
)
all_types = {
hook_type
for properties in all_hooks.values()
for hook_type in (
properties[0].get("types", []) + properties[0].get("types_or", [])
)
}
return {'all_hooks': all_hooks, 'all_types': all_types}
def main() -> int:
env = get_env()
for template in ALL_TEMPLATES:
template_name, _ = os.path.splitext(template)
env['template_name'] = template_name
with open(f'{template_name}.html', 'w') as html_file:
template_obj = template_lookup.get_template(template)
html_file.write(template_obj.render(**env))
return 0
if __name__ == '__main__':
exit(main())