summaryrefslogtreecommitdiff
path: root/docs/scripts/make_rst.py
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-04-11 18:25:22 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-04-11 18:25:22 +0200
commitcb77d1fe956d6011a5739bce5eddf6f6daf80661 (patch)
tree9ecde24218eb6206d1a0a3120e42085346482515 /docs/scripts/make_rst.py
parent204aeb03daf43e73546077c8f72538ad3b6ac75b (diff)
docs: Introduce old base scripts for handling doc generation
Diffstat (limited to 'docs/scripts/make_rst.py')
-rw-r--r--docs/scripts/make_rst.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/docs/scripts/make_rst.py b/docs/scripts/make_rst.py
new file mode 100644
index 0000000..78126b4
--- /dev/null
+++ b/docs/scripts/make_rst.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+import argparse
+import json
+import jinja2
+from pathlib import Path
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ description="Generates source files based on a jinja2 template "
+ "and a json variable map")
+ parser.add_argument(
+ '-t', '--template', required=True,
+ help='path to the jinja2 template dir')
+ parser.add_argument(
+ '-m', '--map', required=True,
+ help='path to the json variable map file')
+ parser.add_argument(
+ '-o', '--output', required=True,
+ help='path to the output dir')
+ parser.add_argument(
+ '--title', default="C++ API Reference",
+ help='The title of the index for the API'
+ );
+
+ return parser.parse_args()
+
+
+def read_template(path):
+ with open(path, "r") as f:
+ return jinja2.Template(f.read(), keep_trailing_newline=True)
+
+
+def read_var_map(path):
+ with open(path, "r") as f:
+ return json.loads(f.read());
+ #endwith
+
+
+def main():
+ args = parse_args()
+
+ template_dir = Path(args.template);
+ template = read_template(template_dir/"class.rst.tmpl");
+ var_map = read_var_map(args.map);
+
+ var_map['title'] = args.title;
+
+ out_dir = Path(args.output);
+ for k,v in var_map["classes"].items():
+ out_name = k+".rst";
+ out_file = out_dir / out_name;
+ v["specializations"] = sorted(v["specializations"], key=lambda k: k["name"]);
+ with open(out_file, "w") as f:
+ f.write(template.render(v));
+ #endwith
+ #endfor
+
+ out_globs = out_dir / "globals.rst";
+ template_globs = read_template(template_dir/"globals.rst.tmpl");
+ with open(out_globs, "w") as f:
+ f.write(template_globs.render(var_map));
+ #endwith
+
+ out_index = out_dir / "index.rst";
+ template_index = read_template(template_dir/"index.rst.tmpl");
+ var_map["classes"] = dict(sorted(var_map["classes"].items(), key=lambda k: k[1]["name"]));
+ with open(out_index, "w") as f:
+ f.write(template_index.render(var_map));
+ pass
+
+if __name__ == "__main__":
+ main();