diff --git a/cookbook/helper/template_helper.py b/cookbook/helper/template_helper.py index 7cabc7d8a..c0928b079 100644 --- a/cookbook/helper/template_helper.py +++ b/cookbook/helper/template_helper.py @@ -7,10 +7,29 @@ from cookbook.helper.mdx_attributes import MarkdownFormatExtension from cookbook.helper.mdx_urlize import UrlizeExtension +class IngredientObject(object): + amount = None + unit = None + food = None + + def __init__(self, ingredient): + self.amount = f'[[calculateAmount({ingredient.amount})]]' + self.unit = ingredient.unit + self.food = ingredient.food + + def __str__(self): + return f'{self.amount} {self.unit} {self.food}' + + def render_instructions(step): # TODO deduplicate markdown cleanup code + ingredients = [] + + for i in step.ingredients.all(): + ingredients.append(IngredientObject(i)) + template = Template(step.instruction) - instructions = template.render(ingredients=step.ingredients.all()) + instructions = template.render(ingredients=ingredients) tags = markdown_tags + ['pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead'] parsed_md = md.markdown(instructions, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()])