Bopytex/bopytex/worker/generate.py

22 lines
523 B
Python

from jinja2.environment import Template
from bopytex.message import Message
def generate(args, deps, output):
env = args["jinja2"]["environment"]
template = env.get_template(deps[0])
try:
with open(output, "w") as out:
out.write(tpl2tex(template, metas=args))
return Message(0, [f"GENERATE - {deps[0]} to {output}"], [])
except Exception as e:
return Message(0, [], [e])
def tpl2tex(template: Template, metas: dict = {}) -> str:
return template.render(metas)