step sections
This commit is contained in:
parent
98c77cb102
commit
e4890b6fd8
3 changed files with 48 additions and 11 deletions
|
@ -205,6 +205,14 @@ class IngredientInstance(Element):
|
|||
price=price,
|
||||
)
|
||||
|
||||
class StepSection(Element):
|
||||
def __init__(self, ctx: Context, title: str, steps: List[str]) -> None:
|
||||
self.title = title
|
||||
self.steps = steps
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
||||
return cls(ctx, dct["section"], dct["steps"])
|
||||
|
||||
class Recipe(Element):
|
||||
def __init__(
|
||||
|
@ -214,7 +222,7 @@ class Recipe(Element):
|
|||
ingredients: List[IngredientInstance],
|
||||
subrecipes: List["Recipe"],
|
||||
price: Optional["PriceDB"],
|
||||
steps: List[str],
|
||||
stepsections: List[StepSection],
|
||||
) -> None:
|
||||
super().__init__(ctx)
|
||||
self.srcpath = ""
|
||||
|
@ -223,7 +231,7 @@ class Recipe(Element):
|
|||
self.ingredients = ingredients
|
||||
self.subrecipes = subrecipes
|
||||
self.price = price
|
||||
self.steps = steps
|
||||
self.stepsections = stepsections
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
||||
|
@ -268,16 +276,24 @@ class Recipe(Element):
|
|||
currency=currency,
|
||||
)
|
||||
|
||||
steps = []
|
||||
stepsections: List[StepSection] = []
|
||||
if "steps" in dct:
|
||||
steps = dct["steps"]
|
||||
defaultstepsection = StepSection(ctx, "default", [])
|
||||
stepsections = [defaultstepsection]
|
||||
for step in dct["steps"]:
|
||||
if isinstance(step, str):
|
||||
defaultstepsection.steps.append(step)
|
||||
if isinstance(step, dict):
|
||||
section = StepSection.from_dict(ctx, step)
|
||||
stepsections.append(section)
|
||||
|
||||
return cls(
|
||||
ctx=ctx,
|
||||
title=dct["title"],
|
||||
ingredients=ingredients,
|
||||
subrecipes=subrecipes,
|
||||
price=price,
|
||||
steps=steps,
|
||||
stepsections=stepsections,
|
||||
)
|
||||
|
||||
class Conversion(Element):
|
||||
|
|
|
@ -26,7 +26,23 @@
|
|||
},
|
||||
"steps": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{ "type": "string" },
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [ "section" ],
|
||||
"properties": {
|
||||
"section": { "type": "string" },
|
||||
"steps": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"subrecipes": {
|
||||
"type": "array",
|
||||
|
|
|
@ -24,11 +24,16 @@
|
|||
{% endfor %}
|
||||
{% if rec.price != None %}price: {{price(rec.price)}}{%endif%}
|
||||
{% endif %}
|
||||
{% if rec.steps|length != 0 %}
|
||||
<h3>Steps</h3>
|
||||
{% for step in rec.steps %}
|
||||
<li>{{ step }}</li>
|
||||
{% endfor %}
|
||||
{% if rec.stepsections|length != 0 %}
|
||||
<h3>Steps</h3>
|
||||
{% for stepsection in rec.stepsections %}
|
||||
{% if stepsection.title != "default" %}
|
||||
<h4>{{stepsection.title}}</h4>
|
||||
{% endif %}
|
||||
{% for step in stepsection.steps %}
|
||||
<li>{{ step }}</li>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<hr>
|
||||
{%- endmacro %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue