init: Initial commit

This commit is contained in:
Björn Benouarets
2026-01-19 14:14:54 +01:00
commit ee9903b704
15 changed files with 18072 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import os
import json
import re
class Template:
def __init__(self, name: str) -> None:
self.__name = name
self.__path = "templates/" + name + ".json"
self.__template = json.load(open(self.__path))
def __str__(self) -> str:
return json.dumps(self.__template)
def replace_placeholders(self, data: dict) -> dict:
"""Return the template as a dictionary with placeholders replaced."""
template_str = json.dumps(self.__template)
for key, value in data.items():
template_str = template_str.replace(f'{{{{{key}}}}}', str(value))
return json.loads(template_str)
def render(self, data: dict) -> str:
"""Return the template as a JSON string with placeholders replaced."""
return json.dumps(self.replace_placeholders(data))