Skip to content

Commit

Permalink
Merge branch 'release/4.0.7' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 24, 2023
2 parents edb7763 + 147b2ab commit 20c1b50
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Recipe Changelog

## 4.0.7 - 2023.02.23
### Fixed
* Fixed an issue where the Nutritional Information display didn't take into account the number of servings ([#66](https://github.com/nystudio107/craft-recipe/issues/66))

## 4.0.6 - 2023.02.22
### Fixed
* Fix API Requests ([#65](https://github.com/nystudio107/craft-recipe/pull/65))
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-recipe",
"description": "A comprehensive recipe FieldType for Craft CMS that includes metric/imperial conversion, portion calculation, and JSON-LD microdata support",
"type": "craft-plugin",
"version": "4.0.6",
"version": "4.0.7",
"keywords": [
"craft",
"cms",
Expand Down
60 changes: 39 additions & 21 deletions src/templates/recipe-nutrition-facts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
.recipe-plugin-nutrition-label table tr.recipe-plugin-thick-row td {
border-top: 4px solid #000;
}
.recipe-plugin-nutrition-label table tr.recipe-plugin-micros li:nth-child(1n+0) {
padding-right: 8px;
}
Expand All @@ -92,6 +93,7 @@
.recipe-plugin-nutrition-label table tr.recipe-plugin-micros li {
border-top: 1px solid #000;
}
.recipe-plugin-nutrition-label table tr.recipe-plugin-micros li {
box-sizing: border-box;
float: left;
Expand All @@ -106,19 +108,32 @@
}
</style>

{% macro percentage(numerator, denomoninator) %}
{% set result = (numerator * 100) / denomoninator %}

{% macro percentage(numerator, denomoninator, serves = 1) %}
{% if serves is empty %}
{% set serves = 1 %}
{% endif %}
{% set result = ((numerator / serves) * 100) / denomoninator %}
{{ result | number_format(0) ~ '%' }}
{% endmacro %}
{% from _self import percentage %}
{% from _self import percentage %}

{% macro servesValue(value, serves) %}
{% set result = value / serves %}
{{- result | number_format(0) -}}
{% endmacro %}
{% from _self import servesValue %}

<div class="recipe-plugin-label">
<div class="recipe-plugin-label-wrapper">
<div class="recipe-plugin-nutrition-label">
<header class="recipe-plugin-label-header">
<h1 class="recipe-plugin-label-title">Nutrition Facts</h1>
{% if value.servingSize | length %}
<div class="recipe-plugin-detail">Serving Size: {{ value.servingSize }}</div>
<div class="recipe-plugin-detail">Serving
{% set servingSizeParts = value.servingSize | split(' ') %}
Size: {{ servesValue(servingSizeParts[0], value.serves) ~ ' ' ~ servingSizeParts[1] ?? '' }}
</div>
{% endif %}
{% if value.serves | length %}
<div class="recipe-plugin-detail">Serves: {{ value.serves }}</div>
Expand All @@ -134,70 +149,73 @@
{% if value.calories | length %}
<tr class="recipe-plugin-calories-row">
<td colspan="2"><b>Calories:</b></td>
<td>{{ value.calories }}</td>
<td>{{ servesValue(value.calories, value.serves) }}</td>
</tr>
{% endif %}
<tr class="recipe-plugin-thick-row">
<td colspan="3" class="recipe-plugin-small-info"><b>% Daily Value*</b></td>
</tr>
{% if value.fatContent | length %}
<tr class="recipe-plugin-macros">
<td colspan="2"><b>Total Fat:</b> {{ value.fatContent ~ 'g' }}</td>
<td><b>{{ percentage(value.fatContent, rda.fatContent) }}</b></td>
<td colspan="2"><b>Total Fat:</b> {{ servesValue(value.fatContent, value.serves) ~ 'g' }}</td>
<td><b>{{ percentage(value.fatContent, rda.fatContent, value.serves) }}</b></td>
</tr>
{% endif %}
{% if value.saturatedFatContent | length %}
<tr class="recipe-plugin-macros">
<td class="recipe-plugin-indent"></td>
<td>Saturated Fat: {{ value.saturatedFatContent ~ 'g' }}</td>
<td>Saturated Fat: {{ servesValue(value.saturatedFatContent, value.serves) ~ 'g' }}</td>
<td>
</td>
</tr>
{% endif %}
{% if value.transFatContent | length %}
<tr class="recipe-plugin-macros">
<td class="recipe-plugin-indent"></td>
<td>Trans Fat: {{ value.transFatContent ~ 'g' }}</td>
<td>Trans Fat: {{ servesValue(value.transFatContent, value.serves) ~ 'g' }}</td>
<td>
</td>
</tr>
{% endif %}
{% if value.cholesterolContent | length %}
<tr class="recipe-plugin-macros">
<td colspan="2"><b>Cholesterol:</b> {{ value.cholesterolContent ~ 'mg' }}</td>
<td><b>{{ percentage(value.cholesterolContent, rda.cholesterolContent) }}</b></td>
<td colspan="2">
<b>Cholesterol:</b> {{ servesValue(value.cholesterolContent, value.serves) ~ 'mg' }}</td>
<td><b>{{ percentage(value.cholesterolContent, rda.cholesterolContent, value.serves) }}</b></td>
</tr>
{% endif %}
{% if value.sodiumContent | length %}
<tr class="recipe-plugin-macros">
<td colspan="2"><b>Sodium:</b> {{ value.sodiumContent ~ 'mg' }}</td>
<td><b>{{ percentage(value.sodiumContent, rda.sodiumContent) }}</b></td>
<td colspan="2"><b>Sodium:</b> {{ servesValue(value.sodiumContent, value.serves) ~ 'mg' }}</td>
<td><b>{{ percentage(value.sodiumContent, rda.sodiumContent, value.serves) }}</b></td>
</tr>
{% endif %}
{% if value.carbohydrateContent | length %}
<tr class="recipe-plugin-macros">
<td colspan="2"><b>Total Carbohydrate:</b> {{ value.carbohydrateContent ~ 'g' }}</td>
<td><b>{{ percentage(value.carbohydrateContent, rda.carbohydrateContent) }}</b></td>
<td colspan="2"><b>Total
Carbohydrate:</b> {{ servesValue(value.carbohydrateContent, value.serves) ~ 'g' }}</td>
<td><b>{{ percentage(value.carbohydrateContent, rda.carbohydrateContent, value.serves) }}</b>
</td>
</tr>
{% endif %}
{% if value.fiberContent | length %}
<tr class="recipe-plugin-macros">
<td class="recipe-plugin-indent"></td>
<td>Dietary Fiber: {{ value.fiberContent ~ 'g' }}</td>
<td><b>{{ percentage(value.fiberContent, rda.fiberContent) }}</b></td>
<td>Dietary Fiber: {{ servesValue(value.fiberContent, value.serves) ~ 'g' }}</td>
<td><b>{{ percentage(value.fiberContent, rda.fiberContent, value.serves) }}</b></td>
</tr>
{% endif %}
{% if value.sugarContent | length %}
<tr class="recipe-plugin-macros">
<td class="recipe-plugin-indent"></td>
<td>Sugars: {{ value.sugarContent ~ 'g' }}</td>
<td><b>{{ percentage(value.sugarContent, rda.sugarContent) }}</b></td>
<td>Sugars: {{ servesValue(value.sugarContent, value.serves) ~ 'g' }}</td>
<td><b>{{ percentage(value.sugarContent, rda.sugarContent, value.serves) }}</b></td>
</tr>
{% endif %}
{% if value.proteinContent | length %}
<tr class="recipe-plugin-macros">
<td colspan="2"><b>Protein:</b> {{ value.proteinContent ~ 'g' }}</td>
<td><b>{{ percentage(value.proteinContent, rda.proteinContent) }}</b></td>
<td colspan="2"><b>Protein:</b> {{ servesValue(value.proteinContent, value.serves) ~ 'g' }}</td>
<td><b>{{ percentage(value.proteinContent, rda.proteinContent, value.serves) }}</b></td>
</tr>
{% endif %}

Expand Down

0 comments on commit 20c1b50

Please sign in to comment.