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 = "" -%}
|
||||
{%- if item[0][0] -%}
|
||||
{%- assign to = item[0][1] | fractionalise -%}
|
||||
{%- assign amount = item[0][0] | fractionalise | append: " to " | append: to | append: " " -%}
|
||||
{%- assign to = item[0][1] | fractionalise: 10 -%}
|
||||
{%- assign amount = item[0][0] | fractionalise: 10 | append: " to " | append: to | append: " " -%}
|
||||
{%- elsif item[0] == 0 -%}
|
||||
{%- assign amount = "" -%}
|
||||
{%- assign end = " to taste" -%}
|
||||
{%- else -%}
|
||||
{%- assign amount = item[0] | fractionalise | append: " " -%}
|
||||
{%- assign amount = item[0] | fractionalise: 10 | append: " " -%}
|
||||
{%- endif -%}
|
||||
|
||||
<{{ tag }}>{{ amount }} {%- if item[2] %}{{ item[2] }} of {% endif -%} {{ item[1] }}{{ end }}</li>
|
||||
|
|
|
@ -3,7 +3,7 @@ require "jekyll"
|
|||
|
||||
module Jekyll
|
||||
module FractionaliseFilter
|
||||
def fractionalise(input)
|
||||
def fractionalise(input, limit = 0)
|
||||
input = input.to_s
|
||||
|
||||
if not input.include? "."
|
||||
|
@ -29,6 +29,11 @@ module Jekyll
|
|||
decimal.to_r
|
||||
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>"
|
||||
|
||||
end
|
||||
|
|
|
@ -160,6 +160,9 @@ a.recipe-listing {
|
|||
width: min-content;
|
||||
vertical-align: top;
|
||||
}
|
||||
.fraction .numerator {
|
||||
text-align: center;
|
||||
}
|
||||
.fraction .denominator {
|
||||
border-top: thin black solid;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue