diff --git a/app/adapters/meal.js b/app/adapters/meal.js index 3183cb1..c6f0189 100644 --- a/app/adapters/meal.js +++ b/app/adapters/meal.js @@ -21,6 +21,7 @@ function normalize(obj) { let attributes = {}; Object.keys(obj).forEach(key => attributes[cleanKey(key)] = obj[key]); + attributes.ingredients = groupByKeyPrefix('ingredient', attributes); return { data: { @@ -38,3 +39,13 @@ function cleanKey(key) { if (key === 'meal') key = 'name'; return key; } + +function groupByKeyPrefix(keyPrefix, obj) { + let resultingArray = []; + Object.keys(obj).forEach(key => { + let value = obj[key]; + if (!value) return; + if (key.startsWith(keyPrefix)) resultingArray.push(value); + }); + return resultingArray; +} diff --git a/app/components/recipe-preview.hbs b/app/components/recipe-preview.hbs index d48ad70..7b1f59b 100644 --- a/app/components/recipe-preview.hbs +++ b/app/components/recipe-preview.hbs @@ -9,7 +9,9 @@ {{@meal.name}}

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. + {{#each @meal.ingredients as |ingredient|}} + {{ingredient}} + {{/each}}

diff --git a/app/models/meal.js b/app/models/meal.js index 46e406c..cc7aeaf 100644 --- a/app/models/meal.js +++ b/app/models/meal.js @@ -8,6 +8,7 @@ export default class MealModel extends Model { @attr area; @attr mealThumb; @attr instructions; + @attr ingredients; @attr tags; @attr youtube; @attr source;