diff --git a/templating/README.md b/templating/README.md new file mode 100644 index 00000000..c1992334 --- /dev/null +++ b/templating/README.md @@ -0,0 +1,21 @@ +This folder contains the templates and templating system for creating the spec. +We use the templating system Jinja2 in Python. This was chosen over other +systems such as Handlebars.js and Templetor because we already have a Python +dependency on the spec build system, and Jinja provides a rich set of template +operations beyond basic control flow. + +Installation +------------ +``` + $ pip install Jinja2 +``` + +Running +------- +To build the spec: +``` + $ python build.py +``` + +This will output ``spec.rst`` which can then be fed into the RST->HTML +converter located in ``matrix-doc/scripts``. diff --git a/templating/build.py b/templating/build.py new file mode 100644 index 00000000..b2e4266d --- /dev/null +++ b/templating/build.py @@ -0,0 +1,18 @@ +from jinja2 import Environment, FileSystemLoader +import json + +def jsonify(input): + return json.dumps(input, indent=4) + +env = Environment(loader=FileSystemLoader("templates")) +env.filters["jsonify"] = jsonify + +example = {} +with open("../example.json", "r") as f: + example = json.loads(f.read()) +event = {} +with open("../event_schema.json", "r") as f: + event = json.loads(f.read()) + +template = env.get_template("events.tmpl") +print template.render(example=example, event=event) diff --git a/templating/templates/events.tmpl b/templating/templates/events.tmpl new file mode 100644 index 00000000..512f7a2e --- /dev/null +++ b/templating/templates/events.tmpl @@ -0,0 +1,7 @@ +{{event.type}} +-------------- +Summary: {{event.summary}} +Type: {{event.parent}} +Description: {{event.desc}} +JSON Format: {{event.content | jsonify}} +Example: {{example.content | jsonify}}