rename parts to subrecipes
This commit is contained in:
parent
6b31462d2c
commit
353aee80cb
3 changed files with 31 additions and 21 deletions
40
recipes.py
40
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"))
|
||||
sys.exit(builder.build("recipes"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue