logo

Grimgrains

Unnamed repository; edit this file 'description' to name the repository.
commit: da3493f6b30bfb315877200a5dd193bb93397bb1
parent 5ca58d80af0d45c7ed4c534ab8ca027a0b57e08b
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sun, 13 Jan 2019 11:53:58 +1200

Added temperature conversion

Diffstat:

Mscripts/templates/recipe.js18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/scripts/templates/recipe.js b/scripts/templates/recipe.js @@ -46,7 +46,7 @@ function RecipeTemplate (id, rect) { var count = 1 for (cat in recipe.INST) { html += `<h3>Step ${count}: ${cat.capitalize()}</h3>` - var category = recipe.INST[cat] + var category = recipe.INST[cat].map(convertTemperatures) html += new Runic(category).toString() count += 1 } @@ -54,6 +54,22 @@ function RecipeTemplate (id, rect) { return `<div id='instructions'>${html}</div>` } + function formatTemperature (temperature) { + const celcius = (parseInt(temperature) - 32) / 1.8 + return `${temperature}°F(${parseInt(celcius / 10) * 10}°C)` + } + + function convertTemperatures (content) { + const parts = content.match(/[^{\}]+(?=})/g) + for (const id in parts) { + const part = parts[id] + if (part.substr(0, 1) === '#' && part.substr(-2, 2) === 'F#') { + content = content.replace(`{${part}}`, `{#${formatTemperature(part.substr(1, part.length - 3))}#}`) + } + } + return content + } + function make_related (q) { var html = '' var recipe = q.result