This repository was archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathbuild.py
More file actions
34 lines (28 loc) · 1.36 KB
/
Copy pathbuild.py
File metadata and controls
34 lines (28 loc) · 1.36 KB
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
import yaml
import sys
import os
from jinja2 import Template, Environment, FileSystemLoader, select_autoescape
class Builder:
def __init__(self, conf_path):
self.templates_path = "./docs/templates/"
self.env = Environment(
loader=FileSystemLoader(self.templates_path),
autoescape=select_autoescape(["html", "md"]))
self.data = {}
with open(conf_path, "r") as conf:
try:
self.data = yaml.safe_load(conf)
except yaml.YAMLError as exc:
if hasattr(exc, 'problem_mark'):
mark = exc.problem_mark
print("Invalid syntax")
def render_template(self, destination, template_name):
template = self.env.get_template(template_name)
with open(self.data["docs_dir"] + "/" + destination, "w") as dest:
dest.write(template.render(self.data))
def render_all_templates(self):
for dest, temp in self.data["templates"].items():
self.render_template(dest, temp)
if __name__ == "__main__":
renderer = Builder(sys.argv[1])
renderer.render_all_templates()