init: render md from json template
This commit is contained in:
commit
150bb16220
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
|
|
@ -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
|
||||
10
.idea/autolegal.iml
Normal file
10
.idea/autolegal.iml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
8
examples/input.json
Normal file
8
examples/input.json
Normal file
|
|
@ -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"
|
||||
}
|
||||
31
main.py
Normal file
31
main.py
Normal file
|
|
@ -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()
|
||||
27
templates/doc.md.j2
Normal file
27
templates/doc.md.j2
Normal file
|
|
@ -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 %}
|
||||
Loading…
Reference in a new issue