updated vue and vue bootrap + template improvements

This commit is contained in:
vabene1111
2021-01-05 22:53:08 +01:00
parent 738b601462
commit fdeede5717
5 changed files with 46 additions and 20 deletions

View File

@ -1,24 +1,35 @@
import bleach import bleach
import markdown as md import markdown as md
from bleach_whitelist import markdown_tags, markdown_attrs from bleach_whitelist import markdown_tags, markdown_attrs
from jinja2 import Template from jinja2 import Template, TemplateSyntaxError
from cookbook.helper.mdx_attributes import MarkdownFormatExtension from cookbook.helper.mdx_attributes import MarkdownFormatExtension
from cookbook.helper.mdx_urlize import UrlizeExtension from cookbook.helper.mdx_urlize import UrlizeExtension
class IngredientObject(object): class IngredientObject(object):
amount = None amount = ""
unit = None unit = ""
food = None food = ""
note = ""
def __init__(self, ingredient): def __init__(self, ingredient):
if ingredient.no_amount:
self.amount = ""
else:
self.amount = f'[[calculateAmount({ingredient.amount})]]' self.amount = f'[[calculateAmount({ingredient.amount})]]'
if ingredient.unit:
self.unit = ingredient.unit self.unit = ingredient.unit
else:
self.unit = ""
self.food = ingredient.food self.food = ingredient.food
self.note = ingredient.note
def __str__(self): def __str__(self):
return f'{self.amount} {self.unit} {self.food}' ingredient = self.amount
if self.unit != "":
ingredient += f' {self.unit}'
return f'{ingredient} {self.food}'
def render_instructions(step): # TODO deduplicate markdown cleanup code def render_instructions(step): # TODO deduplicate markdown cleanup code
@ -28,8 +39,11 @@ def render_instructions(step): # TODO deduplicate markdown cleanup code
for i in step.ingredients.all(): for i in step.ingredients.all():
ingredients.append(IngredientObject(i)) ingredients.append(IngredientObject(i))
try:
template = Template(step.instruction) template = Template(step.instruction)
instructions = template.render(ingredients=ingredients) instructions = template.render(ingredients=ingredients)
except TemplateSyntaxError:
instructions = step.instruction
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()])

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
/*! /*!
* Vue.js v2.6.11 * Vue.js v2.6.12
* (c) 2014-2019 Evan You * (c) 2014-2020 Evan You
* Released under the MIT License. * Released under the MIT License.
*/ */
(function (global, factory) { (function (global, factory) {
@ -5443,7 +5443,7 @@
value: FunctionalRenderContext value: FunctionalRenderContext
}); });
Vue.version = '2.6.11'; Vue.version = '2.6.12';
/* */ /* */
@ -7649,7 +7649,7 @@
// skip the update if old and new VDOM state is the same. // skip the update if old and new VDOM state is the same.
// `value` is handled separately because the DOM value may be temporarily // `value` is handled separately because the DOM value may be temporarily
// out of sync with VDOM state due to focus, composition and modifiers. // out of sync with VDOM state due to focus, composition and modifiers.
// This #4521 by skipping the unnecesarry `checked` update. // This #4521 by skipping the unnecessary `checked` update.
cur !== oldProps[key] cur !== oldProps[key]
) { ) {
// some property updates can throw // some property updates can throw
@ -9894,7 +9894,7 @@
} }
}, },
comment: function comment (text, start, end) { comment: function comment (text, start, end) {
// adding anyting as a sibling to the root node is forbidden // adding anything as a sibling to the root node is forbidden
// comments should still be allowed, but ignored // comments should still be allowed, but ignored
if (currentParent) { if (currentParent) {
var child = { var child = {

File diff suppressed because one or more lines are too long

View File

@ -325,6 +325,10 @@
@click="ingredient.no_amount = false"><i @click="ingredient.no_amount = false"><i
class="fas fa-balance-scale-right fa-fw"></i> {% trans 'Enable Amount' %} class="fas fa-balance-scale-right fa-fw"></i> {% trans 'Enable Amount' %}
</button> </button>
<button type="button" class="dropdown-item"
@click="copyTemplateReference(index)"><i
class="fas fa-code"></i> {% trans 'Copy Template Reference' %}
</button>
</div> </div>
</div> </div>
@ -699,6 +703,14 @@
}, },
removeNutrition: function () { removeNutrition: function () {
this.recipe.nutrition = null this.recipe.nutrition = null
},
copyTemplateReference: function (index) {
const el = document.createElement('textarea');
el.value = `\u007B\u007B ingredients[${index}] \u007D\u007D`;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
} }
} }
}); });