Added script for generating modules.

This commit is contained in:
2025-06-19 15:40:48 +02:00
parent 34730454ae
commit 9bfbd44e34
8 changed files with 326 additions and 25 deletions

View File

@@ -34,11 +34,16 @@ def make_env(filters: Optional[dict[str, Callable]] = None,
return jinja_env
def generate_file(template: str, target: Path, context: dict[str, Any], **kwargs) -> None:
def generate_file(template_name: str, target: Path, context: dict[str, Any], **kwargs) -> None:
jinja_env = make_env(**kwargs)
template = jinja_env.get_template(template)
template = jinja_env.get_template(template_name)
result = template.render(**context)
target.parent.mkdir(parents=True, exist_ok=True)
with target.open('w') as f:
f.write(result)
def render_string(input: str, context: dict[str, Any], **kwargs) -> str:
jinja_env = make_env(**kwargs)
template = jinja_env.from_string(input)
return template.render(**context)