templating working

This commit is contained in:
vabene1111
2021-01-05 22:07:46 +01:00
parent 2c93a2f177
commit 738b601462

View File

@@ -7,10 +7,29 @@ from cookbook.helper.mdx_attributes import MarkdownFormatExtension
from cookbook.helper.mdx_urlize import UrlizeExtension 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 def render_instructions(step): # TODO deduplicate markdown cleanup code
ingredients = []
for i in step.ingredients.all():
ingredients.append(IngredientObject(i))
template = Template(step.instruction) 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'] tags = markdown_tags + ['pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead']
parsed_md = md.markdown(instructions, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()]) parsed_md = md.markdown(instructions, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()])