ruby function for formatting time
This commit is contained in:
parent
1d295e27f5
commit
e6f2077d9b
3 changed files with 20 additions and 17 deletions
|
@ -5,11 +5,8 @@
|
||||||
<p>
|
<p>
|
||||||
By {{ recipe.author }} -
|
By {{ recipe.author }} -
|
||||||
{% if recipe.difficulty %}Difficulty: <span class='stars'>{{ recipe.difficulty | to_stars }}</span> - {%- endif %}
|
{% if recipe.difficulty %}Difficulty: <span class='stars'>{{ recipe.difficulty | to_stars }}</span> - {%- endif %}
|
||||||
{{ recipe.method | size }} steps {%- if recipe.time %} -
|
{{ recipe.method | size }} steps
|
||||||
{%- if recipe.time > 59 %} {{ recipe.time | divided_by: 60}}h {% endif -%}
|
{%- if recipe.time %} - {{ recipe.time | hours_and_minutes: false }}{%- endif -%}
|
||||||
{% assign mins = recipe.time | modulo: 60 -%}
|
|
||||||
{%- if mins > 0 %}{{ mins }}m{% endif %}
|
|
||||||
{%- endif -%}
|
|
||||||
</p>
|
</p>
|
||||||
<ol class='excerpt'>
|
<ol class='excerpt'>
|
||||||
{% for step in recipe.method | limit: 4 %}
|
{% for step in recipe.method | limit: 4 %}
|
||||||
|
|
|
@ -17,18 +17,7 @@ custom_h1: true
|
||||||
<h1 class='scrolling'>{{ page.name }}</h1>
|
<h1 class='scrolling'>{{ page.name }}</h1>
|
||||||
<h1 class='invisible'>{{ page.name }}</h1>
|
<h1 class='invisible'>{{ page.name }}</h1>
|
||||||
{%- if page.time -%}
|
{%- if page.time -%}
|
||||||
{%- if page.time > 59 %}
|
{%- assign time = page.time | hours_and_minutes -%}
|
||||||
{%- assign hours = page.time | divided_by: 60 -%}
|
|
||||||
{%- assign minutes = page.time | modulo: 60 -%}
|
|
||||||
{%- assign time = hours | append: " hour" -%}
|
|
||||||
{%- if hours > 1 %}{% assign time = time | append: "s" %}{% endif -%}
|
|
||||||
{%- if minutes > 0 -%}
|
|
||||||
{%- assign time = time | append: " " | append: minutes | append: " minute" -%}
|
|
||||||
{%- if minutes > 1 %}{% assign time = time | append: "s" %}{% endif -%}
|
|
||||||
{%- endif -%}
|
|
||||||
{%- else -%}
|
|
||||||
{%- assign time = page.time %}
|
|
||||||
{%- endif -%}
|
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
<p class='subtle'>{% if page.difficulty %}Difficulty: <span class='stars'>{{ page.difficulty | to_stars }}</span> - {% endif %}{{ page.method.size }} steps - Estimated cooking time: {{ time | default: "Not provided" }} {% if page.author %} - By {{ page.author }} {% endif %}</p>
|
<p class='subtle'>{% if page.difficulty %}Difficulty: <span class='stars'>{{ page.difficulty | to_stars }}</span> - {% endif %}{{ page.method.size }} steps - Estimated cooking time: {{ time | default: "Not provided" }} {% if page.author %} - By {{ page.author }} {% endif %}</p>
|
||||||
|
|
|
@ -57,6 +57,23 @@ module Jekyll
|
||||||
|
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hours_and_minutes(input, long = true)
|
||||||
|
time = input.to_i.divmod(60)
|
||||||
|
hours, minutes = "h", "m"
|
||||||
|
if long
|
||||||
|
hours = " hour" + (time[0] > 1 ? "s" : "") + " "
|
||||||
|
minutes = " minute" + (time[1] > 1 ? "s" : "") + " "
|
||||||
|
end
|
||||||
|
|
||||||
|
if time[1] == 0
|
||||||
|
"#{time[0]}#{hours}"
|
||||||
|
elsif time[0] == 0
|
||||||
|
"#{time[1]}#{minutes}"
|
||||||
|
else
|
||||||
|
"#{time[0]}#{hours}#{time[1]}#{minutes}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue