From 150bb16220b03e68360e072c127d6f532d2baf43 Mon Sep 17 00:00:00 2001 From: rsxri Date: Tue, 6 Jan 2026 16:41:06 +0000 Subject: [PATCH] init: render md from json template --- .idea/.gitignore | 8 ++++++++ .idea/autolegal.iml | 10 ++++++++++ examples/input.json | 8 ++++++++ main.py | 31 +++++++++++++++++++++++++++++++ templates/doc.md.j2 | 27 +++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/autolegal.iml create mode 100644 examples/input.json create mode 100644 main.py create mode 100644 templates/doc.md.j2 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/autolegal.iml b/.idea/autolegal.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/autolegal.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/examples/input.json b/examples/input.json new file mode 100644 index 0000000..c5ac471 --- /dev/null +++ b/examples/input.json @@ -0,0 +1,8 @@ +{ + "client_name": "Acme Ltd", + "provider_name": "John Doe 2", + "payment_type": "hourly", + "hourly_rate_gbp": 40, + "include_confidentiality": false, + "governing_law": "England and Wales" +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..834745f --- /dev/null +++ b/main.py @@ -0,0 +1,31 @@ +import json +from pathlib import Path +from jinja2 import Environment, FileSystemLoader + + +def main(): + # load input data + # path() over hardcoding str + data = json.loads(Path("examples/input.json").read_text(encoding="utf-8")) + + # setup template eng + # create jinja2 env for templates + env = Environment( + # look in templates/ + loader=FileSystemLoader("templates"), + # trim whitespaces + trim_blocks=True, + lstrip_blocks=True, + ) + # load template to render + # **data spreads dict so keys become template vars + template = env.get_template("doc.md.j2") + out = template.render(**data) + + # write output - render md to file + Path("out.md").write_text(out, encoding="utf-8") + print("wrote out.md") + + +if __name__ == "__main__": + main() diff --git a/templates/doc.md.j2 b/templates/doc.md.j2 new file mode 100644 index 0000000..a72a3e0 --- /dev/null +++ b/templates/doc.md.j2 @@ -0,0 +1,27 @@ +# agreement summary + +client: **{{ client_name }}** +provider: **{{ provider_name }}** + +## payment +{% if payment_type == "hourly" %} +rate: **£{{ hourly_rate_gbp }}/hour** +{% elif payment_type == "fixed" %} +fixed fee: **£{{ fixed_fee_gbp }}** +{% else %} +payment: tbd +{% endif %} + +## confidentiality +{% if include_confidentiality %} +included. +{% else %} +not included. +{% endif %} + +## governing law +{% if governing_law == "England and Wales" %} +laws of england and wales. +{% else %} +{{ governing_law }}. +{% endif %} \ No newline at end of file