allow user to limit fraction denominator
This commit is contained in:
parent
4d427690f2
commit
ebcb267739
3 changed files with 12 additions and 4 deletions
|
@ -12,13 +12,13 @@
|
||||||
|
|
||||||
{%- assign end = "" -%}
|
{%- assign end = "" -%}
|
||||||
{%- if item[0][0] -%}
|
{%- if item[0][0] -%}
|
||||||
{%- assign to = item[0][1] | fractionalise -%}
|
{%- assign to = item[0][1] | fractionalise: 10 -%}
|
||||||
{%- assign amount = item[0][0] | fractionalise | append: " to " | append: to | append: " " -%}
|
{%- assign amount = item[0][0] | fractionalise: 10 | append: " to " | append: to | append: " " -%}
|
||||||
{%- elsif item[0] == 0 -%}
|
{%- elsif item[0] == 0 -%}
|
||||||
{%- assign amount = "" -%}
|
{%- assign amount = "" -%}
|
||||||
{%- assign end = " to taste" -%}
|
{%- assign end = " to taste" -%}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{%- assign amount = item[0] | fractionalise | append: " " -%}
|
{%- assign amount = item[0] | fractionalise: 10 | append: " " -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
<{{ tag }}>{{ amount }} {%- if item[2] %}{{ item[2] }} of {% endif -%} {{ item[1] }}{{ end }}</li>
|
<{{ tag }}>{{ amount }} {%- if item[2] %}{{ item[2] }} of {% endif -%} {{ item[1] }}{{ end }}</li>
|
||||||
|
|
|
@ -3,7 +3,7 @@ require "jekyll"
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module FractionaliseFilter
|
module FractionaliseFilter
|
||||||
def fractionalise(input)
|
def fractionalise(input, limit = 0)
|
||||||
input = input.to_s
|
input = input.to_s
|
||||||
|
|
||||||
if not input.include? "."
|
if not input.include? "."
|
||||||
|
@ -29,6 +29,11 @@ module Jekyll
|
||||||
decimal.to_r
|
decimal.to_r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if limit != 0 and rational.denominator > limit
|
||||||
|
# apply a maximum size for the denominator to avoid the (imo) much more readable "0.41" becoming "41/100" unless wanted
|
||||||
|
return input
|
||||||
|
end
|
||||||
|
|
||||||
"<span title='#{input}'>#{leading_integer != "0" ? "#{leading_integer} " : ""}<span class='fraction'><span class='numerator'>#{rational.numerator}</span><span class='denominator'>#{rational.denominator}</span></span></span>"
|
"<span title='#{input}'>#{leading_integer != "0" ? "#{leading_integer} " : ""}<span class='fraction'><span class='numerator'>#{rational.numerator}</span><span class='denominator'>#{rational.denominator}</span></span></span>"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -160,6 +160,9 @@ a.recipe-listing {
|
||||||
width: min-content;
|
width: min-content;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
.fraction .numerator {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
.fraction .denominator {
|
.fraction .denominator {
|
||||||
border-top: thin black solid;
|
border-top: thin black solid;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue