def export_area(templates: Jinja2Templates, areas_dir: str, area: Area) -> None: area_template = templates.get_template("area.html") area_dir = os.path.join(areas_dir, str(area.id)) os.makedirs(area_dir, exist_ok=True) area_path = os.path.join(area_dir, "index.html") with open(area_path, "w") as f: f.write(area_template.render(render_area(area)))
def export_branch( templates: Jinja2Templates, branches_dir: str, area: Area, branch: Branch, ): branch_template = templates.get_template("branch.html") area_branch_dir = os.path.join( branches_dir, str(area.id), str(branch.id) ) os.makedirs(area_branch_dir, exist_ok=True) branch_path = os.path.join(area_branch_dir, "index.html") with open(branch_path, "w") as f: f.write(branch_template.render(render_branch(area, branch)))
def export_storylet( templates: Jinja2Templates, storylets_dir: str, area: Area, storylet: Storylet, ) -> None: storylet_template = templates.get_template("storylet.html") area_storylet_dir = os.path.join( storylets_dir, str(area.id), str(storylet.id) ) os.makedirs(area_storylet_dir, exist_ok=True) storylet_path = os.path.join(area_storylet_dir, "index.html") with open(storylet_path, "w") as f: f.write(storylet_template.render(render_storylet(area, storylet)))
def get_template(templates: Jinja2Templates, template_name: str): return templates.get_template(template_name)