mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
templating working
This commit is contained in:
@@ -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()])
|
||||
|
||||
Reference in New Issue
Block a user