allow user to limit fraction denominator

This commit is contained in:
Lynne Megido 2020-03-06 04:41:18 +10:00
parent 4d427690f2
commit ebcb267739
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 12 additions and 4 deletions

View file

@ -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>

View file

@ -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

View file

@ -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;
}