Skip to content

Commit

Permalink
feat(recipe): add diagonal fractions to recipe ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow81627 committed Dec 28, 2019
1 parent 2e22269 commit a7e3f3c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"eslint.validate": ["vue", "javascript", "javascriptreact"],
"editor.formatOnSave": false,
"vetur.validation.template": false,
"editor.formatOnSave": true,
"vetur.validation.template": true,
"files.exclude": {
"**/node_modules/**": true,
"**/dist/**": true,
Expand Down
2 changes: 2 additions & 0 deletions assets/scss/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
}
}

@import 'utility-opentype';

@import '~/assets/css/print.css' print;
31 changes: 30 additions & 1 deletion components/Recipe/Recipe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
:key="ingredient"
class="list-group-item"
>
{{ ingredient }}
<span v-html="splitFraction(ingredient)" />
</li>
</ol>
</section>
Expand Down Expand Up @@ -132,6 +132,35 @@ export default {
return recipe;
},
},
methods: {
splitFraction(value, sep = '/') {
if (!value) return '';
value = value.toString();
const split = value.split(sep);
if (Array.isArray(split) && split.length >= 2) {
const combined = split.reduce((accumulator, currentValue) => {
const last = accumulator.slice(-1);
if (parseInt(last) && parseInt(currentValue)) {
return (
accumulator.substring(0, accumulator.length - 1) +
'<span class="frac">' +
last +
'/' +
currentValue.charAt(0) +
'</span>' +
currentValue.substr(1)
);
} else {
return accumulator + currentValue;
}
});
return combined;
}
return value;
},
},
head() {
return {
title: this.recipe.name,
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"nuxt-i18n": "6.4.1",
"nuxt-webfontloader": "1.1.0",
"quicklink": "1.0.1",
"quill": "1.3.7"
"quill": "1.3.7",
"utility-opentype": "^0.1.4"
},
"devDependencies": {
"@babel/core": "7.7.7",
Expand Down
40 changes: 10 additions & 30 deletions test/__snapshots__/Recipe.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,16 @@ exports[`Recipe renders properly 1`] = `
<section>
<h2>Ingredients:</h2>
<ol class=\\"list-group-flush pl-0\\">
<li class=\\"list-group-item\\">
1 small onion, diced
</li>
<li class=\\"list-group-item\\">
2 cloves garlic, minced
</li>
<li class=\\"list-group-item\\">
2 carrots, diced small
</li>
<li class=\\"list-group-item\\">
2 stalks celery, diced small
</li>
<li class=\\"list-group-item\\">
2 large cans (28 oz. each) peeled Italian Roma tomatoes
</li>
<li class=\\"list-group-item\\">
1 large bunch fresh basil, washed
</li>
<li class=\\"list-group-item\\">
2 tbsp extra virgin olive oil
</li>
<li class=\\"list-group-item\\">
1 lb. spaghetti pasta
</li>
<li class=\\"list-group-item\\">
Salt to taste
</li>
<li class=\\"list-group-item\\">
Freshly grated Parmigiano-Reggiano cheese
</li>
<li class=\\"list-group-item\\"><span>1 small onion, diced</span></li>
<li class=\\"list-group-item\\"><span>2 cloves garlic, minced</span></li>
<li class=\\"list-group-item\\"><span>2 carrots, diced small</span></li>
<li class=\\"list-group-item\\"><span>2 stalks celery, diced small</span></li>
<li class=\\"list-group-item\\"><span>2 large cans (28 oz. each) peeled Italian Roma tomatoes</span></li>
<li class=\\"list-group-item\\"><span>1 large bunch fresh basil, washed</span></li>
<li class=\\"list-group-item\\"><span>2 tbsp extra virgin olive oil</span></li>
<li class=\\"list-group-item\\"><span>1 lb. spaghetti pasta</span></li>
<li class=\\"list-group-item\\"><span>Salt to taste</span></li>
<li class=\\"list-group-item\\"><span>Freshly grated Parmigiano-Reggiano cheese</span></li>
</ol>
</section>
<section>
Expand Down

0 comments on commit a7e3f3c

Please sign in to comment.