rename parts to subrecipes
This commit is contained in:
parent
6b31462d2c
commit
353aee80cb
3 changed files with 31 additions and 21 deletions
38
recipes.py
38
recipes.py
|
@ -208,7 +208,7 @@ class IngredientInstance:
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
class RecipePart:
|
class Subrecipe:
|
||||||
def __init__(self, ctx: Context) -> None:
|
def __init__(self, ctx: Context) -> None:
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
|
|
||||||
|
@ -230,24 +230,24 @@ class RecipePart:
|
||||||
class Recipe:
|
class Recipe:
|
||||||
def __init__(self, ctx: Context) -> None:
|
def __init__(self, ctx: Context) -> None:
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.parts: List[RecipePart] = []
|
self.subrecipes: List[Subrecipe] = []
|
||||||
self.srcpath = ""
|
self.srcpath = ""
|
||||||
self.outpath = ""
|
self.outpath = ""
|
||||||
self.title = ""
|
self.title = ""
|
||||||
|
|
||||||
def load(self, dct: Dict[str, Any]) -> List[str]:
|
def load(self, dct: Dict[str, Any]) -> List[str]:
|
||||||
issues: List[str] = []
|
issues: List[str] = []
|
||||||
if "parts" in dct:
|
if "subrecipes" in dct:
|
||||||
self.title = dct["title"]
|
self.title = dct["title"]
|
||||||
|
|
||||||
for partdct in dct["parts"]:
|
for partdct in dct["subrecipes"]:
|
||||||
rp = RecipePart(self.ctx)
|
rp = Subrecipe(self.ctx)
|
||||||
issues += rp.load(partdct)
|
issues += rp.load(partdct)
|
||||||
self.parts.append(rp)
|
self.subrecipes.append(rp)
|
||||||
else:
|
else:
|
||||||
rp = RecipePart(self.ctx)
|
rp = Subrecipe(self.ctx)
|
||||||
issues = rp.load(dct)
|
issues = rp.load(dct)
|
||||||
self.parts = [rp]
|
self.subrecipes = [rp]
|
||||||
self.title = rp.title
|
self.title = rp.title
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ class Builder:
|
||||||
def load(self, dir: str) -> int:
|
def load(self, dir: str) -> int:
|
||||||
issues: List[str] = []
|
issues: List[str] = []
|
||||||
|
|
||||||
unitsdct = self.load_file(dir+"/units.yaml")
|
unitsdct = self.load_file(dir + "/units.yaml")
|
||||||
unitsschema = self.load_file("schemas/units.json")
|
unitsschema = self.load_file("schemas/units.json")
|
||||||
jsonschema.validate(instance=unitsdct, schema=unitsschema)
|
jsonschema.validate(instance=unitsdct, schema=unitsschema)
|
||||||
issues += self.ctx.units.load(unitsdct)
|
issues += self.ctx.units.load(unitsdct)
|
||||||
|
@ -309,7 +309,7 @@ class Builder:
|
||||||
print("ERROR in units.yaml:", issue)
|
print("ERROR in units.yaml:", issue)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
ingredientsdct = self.load_file(dir+"/ingredients.yaml")
|
ingredientsdct = self.load_file(dir + "/ingredients.yaml")
|
||||||
ingredientsschema = self.load_file("schemas/ingredients.json")
|
ingredientsschema = self.load_file("schemas/ingredients.json")
|
||||||
jsonschema.validate(instance=ingredientsdct, schema=ingredientsschema)
|
jsonschema.validate(instance=ingredientsdct, schema=ingredientsschema)
|
||||||
issues += self.ctx.ingredients.load(ingredientsdct)
|
issues += self.ctx.ingredients.load(ingredientsdct)
|
||||||
|
@ -323,7 +323,7 @@ class Builder:
|
||||||
def run(self, dir: str) -> int:
|
def run(self, dir: str) -> int:
|
||||||
issues = []
|
issues = []
|
||||||
files = []
|
files = []
|
||||||
for _, _, filesx in os.walk(dir+"/recipes"):
|
for _, _, filesx in os.walk(dir + "/recipes"):
|
||||||
files = filesx
|
files = filesx
|
||||||
files.sort()
|
files.sort()
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ class Builder:
|
||||||
print(f"unknown extension of {file}")
|
print(f"unknown extension of {file}")
|
||||||
continue
|
continue
|
||||||
recipe = Recipe(self.ctx)
|
recipe = Recipe(self.ctx)
|
||||||
recipedct = self.load_file(dir+"/recipes/" + file)
|
recipedct = self.load_file(dir + "/recipes/" + file)
|
||||||
jsonschema.validate(instance=recipedct, schema=recipeschema)
|
jsonschema.validate(instance=recipedct, schema=recipeschema)
|
||||||
issues += recipe.load(recipedct)
|
issues += recipe.load(recipedct)
|
||||||
recipe.srcpath = file
|
recipe.srcpath = file
|
||||||
|
@ -346,10 +346,20 @@ class Builder:
|
||||||
print("ERROR", issue)
|
print("ERROR", issue)
|
||||||
return 1
|
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:
|
for recipe in recipes:
|
||||||
self.rendertemplate(
|
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
|
return 0
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "type": "string" }
|
"items": { "type": "string" }
|
||||||
},
|
},
|
||||||
"parts": {
|
"subrecipes": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "$ref": "/recipe.json" }
|
"items": { "$ref": "/recipe.json" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
{%block body %}
|
{%block body %}
|
||||||
<a href="index.html">back</a>
|
<a href="index.html">back</a>
|
||||||
<h1>{{recipe.title}}</h1>
|
<h1>{{recipe.title}}</h1>
|
||||||
{% for part in recipe.parts %}
|
{% for subrecipe in recipe.subrecipes %}
|
||||||
{% if recipe.parts|length != 1 %}
|
{% if recipe.subrecipes|length != 1 %}
|
||||||
<h2>{{part.title}}</h2>
|
<h2>{{subrecipe.title}}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h3>Ingredients</h3>
|
<h3>Ingredients</h3>
|
||||||
{% for ing in part.ingredients %}
|
{% for ing in subrecipe.ingredients %}
|
||||||
<li>{{ingredient(ing)}}</li>
|
<li>{{ingredient(ing)}}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<h3>Steps</h3>
|
<h3>Steps</h3>
|
||||||
{% for step in part.steps %}
|
{% for step in subrecipe.steps %}
|
||||||
<li>{{ step }}</li>
|
<li>{{ step }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<hr>
|
<hr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue