From 353aee80cb92ee1fd16e3bc843add41aaa89c830 Mon Sep 17 00:00:00 2001 From: Emi Vasilek Date: Mon, 6 Nov 2023 07:41:55 +0100 Subject: [PATCH] rename parts to subrecipes --- recipes.py | 40 +++++++++++++++++++++++++--------------- schemas/recipe.json | 2 +- templates/recipe.html | 10 +++++----- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/recipes.py b/recipes.py index b3a1233..2f70ed5 100644 --- a/recipes.py +++ b/recipes.py @@ -208,7 +208,7 @@ class IngredientInstance: return issues -class RecipePart: +class Subrecipe: def __init__(self, ctx: Context) -> None: self.ctx = ctx @@ -230,24 +230,24 @@ class RecipePart: class Recipe: def __init__(self, ctx: Context) -> None: self.ctx = ctx - self.parts: List[RecipePart] = [] + self.subrecipes: List[Subrecipe] = [] self.srcpath = "" self.outpath = "" self.title = "" def load(self, dct: Dict[str, Any]) -> List[str]: issues: List[str] = [] - if "parts" in dct: + if "subrecipes" in dct: self.title = dct["title"] - for partdct in dct["parts"]: - rp = RecipePart(self.ctx) + for partdct in dct["subrecipes"]: + rp = Subrecipe(self.ctx) issues += rp.load(partdct) - self.parts.append(rp) + self.subrecipes.append(rp) else: - rp = RecipePart(self.ctx) + rp = Subrecipe(self.ctx) issues = rp.load(dct) - self.parts = [rp] + self.subrecipes = [rp] self.title = rp.title return issues @@ -300,7 +300,7 @@ class Builder: def load(self, dir: str) -> int: issues: List[str] = [] - unitsdct = self.load_file(dir+"/units.yaml") + unitsdct = self.load_file(dir + "/units.yaml") unitsschema = self.load_file("schemas/units.json") jsonschema.validate(instance=unitsdct, schema=unitsschema) issues += self.ctx.units.load(unitsdct) @@ -309,7 +309,7 @@ class Builder: print("ERROR in units.yaml:", issue) return 1 - ingredientsdct = self.load_file(dir+"/ingredients.yaml") + ingredientsdct = self.load_file(dir + "/ingredients.yaml") ingredientsschema = self.load_file("schemas/ingredients.json") jsonschema.validate(instance=ingredientsdct, schema=ingredientsschema) issues += self.ctx.ingredients.load(ingredientsdct) @@ -323,7 +323,7 @@ class Builder: def run(self, dir: str) -> int: issues = [] files = [] - for _, _, filesx in os.walk(dir+"/recipes"): + for _, _, filesx in os.walk(dir + "/recipes"): files = filesx files.sort() @@ -334,7 +334,7 @@ class Builder: print(f"unknown extension of {file}") continue recipe = Recipe(self.ctx) - recipedct = self.load_file(dir+"/recipes/" + file) + recipedct = self.load_file(dir + "/recipes/" + file) jsonschema.validate(instance=recipedct, schema=recipeschema) issues += recipe.load(recipedct) recipe.srcpath = file @@ -346,10 +346,20 @@ class Builder: print("ERROR", issue) return 1 - self.rendertemplate("index.html", "html", "index.html", dir, {"recipes": recipes}) + self.rendertemplate( + templatepath="index.html", + format="html", + file="index.html", + dir=dir, + args={"recipes": recipes}, + ) for recipe in recipes: self.rendertemplate( - "recipe.html", "html", recipe.outpath, dir, {"recipe": recipe} + templatepath="recipe.html", + format="html", + file=recipe.outpath, + dir=dir, + args={"recipe": recipe} ) return 0 @@ -380,4 +390,4 @@ class Builder: if __name__ == "__main__": builder = Builder() - sys.exit(builder.build("recipes")) \ No newline at end of file + sys.exit(builder.build("recipes")) diff --git a/schemas/recipe.json b/schemas/recipe.json index 5793003..3b4c980 100644 --- a/schemas/recipe.json +++ b/schemas/recipe.json @@ -28,7 +28,7 @@ "type": "array", "items": { "type": "string" } }, - "parts": { + "subrecipes": { "type": "array", "items": { "$ref": "/recipe.json" } } diff --git a/templates/recipe.html b/templates/recipe.html index 0d6a17a..92037f4 100644 --- a/templates/recipe.html +++ b/templates/recipe.html @@ -14,16 +14,16 @@ {%block body %} back

{{recipe.title}}

-{% for part in recipe.parts %} -{% if recipe.parts|length != 1 %} -

{{part.title}}

+{% for subrecipe in recipe.subrecipes %} +{% if recipe.subrecipes|length != 1 %} +

{{subrecipe.title}}

{% endif %}

Ingredients

-{% for ing in part.ingredients %} +{% for ing in subrecipe.ingredients %}
  • {{ingredient(ing)}}
  • {% endfor %}

    Steps

    -{% for step in part.steps %} +{% for step in subrecipe.steps %}
  • {{ step }}
  • {% endfor %}