jekyll-theme-recipe 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_layouts/default.html +5 -4
- data/_layouts/post.html +1 -1
- data/_sass/navigation.scss +7 -6
- data/assets/js/servings.js +93 -49
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6219e982c80788d779a5ce2418390608348c30bb8a98013b13a966835e7de7
|
4
|
+
data.tar.gz: 22b5555d7ded586ce5d115845df526bf26b05575b92dc2fd4c9817789f527042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c0196aaa442d24c699051b884619bab1dd1a926665f60eaffb127cba314a353496ec683524ffdbbd8bf8ace6327fce55d0392cfcb23620463adc91e9c547d8
|
7
|
+
data.tar.gz: 2b4e02209a2b5907d13c5cbf0abc3092516169bf7fb8d9c6a65faad46ba588504c2e4fce5380d4ae947fab6f503d13cf1769f6cd38a153b027ce265385e290ab
|
data/_layouts/default.html
CHANGED
@@ -26,10 +26,11 @@
|
|
26
26
|
<body>
|
27
27
|
{% include navigation.html %}
|
28
28
|
<header>
|
29
|
-
|
30
|
-
<
|
31
|
-
|
32
|
-
|
29
|
+
{% if site.data.company_details.logo_image %}
|
30
|
+
<a href="{{site.baseurl }}/">
|
31
|
+
<img src="{{ site.baseurl }}{{ site.data.company_details.logo_image }}" width="180" alt="logo">
|
32
|
+
</a>
|
33
|
+
{% endif %}
|
33
34
|
</header>
|
34
35
|
|
35
36
|
<div class="container main-content">
|
data/_layouts/post.html
CHANGED
data/_sass/navigation.scss
CHANGED
@@ -3,24 +3,25 @@ nav {
|
|
3
3
|
width: 100%;
|
4
4
|
display: flex;
|
5
5
|
justify-content: center;
|
6
|
-
background: rgba(255, 255, 255, .
|
6
|
+
background: rgba(255, 255, 255, .75);
|
7
7
|
z-index: 999;
|
8
8
|
|
9
9
|
a {
|
10
10
|
display: inline-block;
|
11
11
|
text-decoration: none;
|
12
|
-
padding:
|
13
|
-
color:
|
12
|
+
padding: 14px 8px;
|
13
|
+
color: black;
|
14
14
|
text-transform: uppercase;
|
15
15
|
letter-spacing: 1px;
|
16
16
|
font-size: .9em;
|
17
17
|
|
18
18
|
&.active {
|
19
|
-
|
19
|
+
font-weight: bold;
|
20
20
|
}
|
21
21
|
|
22
|
-
&:hover {
|
23
|
-
color: #000;
|
22
|
+
&:hover,&:focus {
|
23
|
+
background-color: #000;
|
24
|
+
color: white;
|
24
25
|
}
|
25
26
|
}
|
26
27
|
}
|
data/assets/js/servings.js
CHANGED
@@ -1,62 +1,106 @@
|
|
1
|
-
|
1
|
+
class Ingredient {
|
2
|
+
constructor(referenceValue, reference){
|
3
|
+
this.referenceValue = this.getDecimalValue(referenceValue);
|
4
|
+
this.reference = reference;
|
5
|
+
}
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
7
|
+
getServingsValue(newServing, oldServing){
|
8
|
+
if(isNaN(this.referenceValue)){
|
9
|
+
return null;
|
10
|
+
}
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
return this.referenceValue * newServing / oldServing;
|
13
|
+
}
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
calcAndRenderNewServingsValue(newServing, oldServing){
|
16
|
+
const newServingsValue = this.trimValue(this.getServingsValue(newServing, oldServing));
|
17
|
+
|
18
|
+
if(newServingsValue != null){
|
19
|
+
this.reference.innerHTML = newServingsValue.toString().includes(".")
|
20
|
+
? this.decimalToFraction(newServingsValue)
|
21
|
+
: newServingsValue;
|
13
22
|
}
|
14
|
-
|
15
|
-
const portionElementValue = portionElements[i].innerHTML.search('/') >=0
|
16
|
-
? fractionToDecimal(portionElements[i].innerHTML)
|
17
|
-
: Number.parseFloat(portionElements[i].innerHTML);
|
18
|
-
|
19
|
-
const newPortionValue = trimNumberAfterDecimalPoint(portionElementValue * newPortion / currentPortion, 3);
|
20
|
-
|
21
|
-
const newPortionString = newPortionValue.toString();
|
22
|
-
portionElements[i].innerHTML = newPortionString.includes('.')
|
23
|
-
? decimalToFraction(newPortionString)
|
24
|
-
: newPortionString;
|
25
23
|
}
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
// "45 1/3" -> "45" (level of precision hinders understanding)
|
26
|
+
trimValue(servingsValue){
|
27
|
+
if(this.referenceValue >= 10){
|
28
|
+
return servingsValue.toFixed(0);
|
29
|
+
}
|
30
|
+
return servingsValue;
|
31
|
+
}
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
toString(){
|
34
|
+
return "value: " + this.referenceValue + ", reference html: " + this.reference.innerHTML;
|
35
|
+
}
|
36
|
+
|
37
|
+
// from: http://jsfiddle.net/5QrhQ/5/ or https://stackoverflow.com/a/23575406
|
38
|
+
decimalToFraction(decimal){
|
39
|
+
var len = decimal.toString().length - 2;
|
40
|
+
|
41
|
+
var denominator = Math.pow(10, len);
|
42
|
+
var numerator = decimal * denominator;
|
43
|
+
|
44
|
+
var divisor = this.gcd(numerator, denominator);
|
45
|
+
|
46
|
+
numerator /= divisor;
|
47
|
+
denominator /= divisor;
|
48
|
+
|
49
|
+
return numerator > denominator
|
50
|
+
? Math.floor(numerator / denominator) + " " + numerator % denominator + '/' + Math.floor(denominator)
|
51
|
+
: Math.floor(numerator) + '/' + Math.floor(denominator);
|
52
|
+
}
|
53
|
+
gcd(a, b) {
|
54
|
+
if (b < 0.0000001) return a; // Since there is a limited precision we need to limit the value.
|
36
55
|
|
37
|
-
|
56
|
+
return this.gcd(b, Math.floor(a % b)); // Discard any fractions due to limitations in precision.
|
57
|
+
};
|
58
|
+
getDecimalValue(value){
|
59
|
+
return value.includes("/")
|
60
|
+
? this.fractionToDecimal(value)
|
61
|
+
: Number.parseFloat(value);
|
62
|
+
}
|
63
|
+
// from https://stackoverflow.com/a/49246271
|
64
|
+
fractionToDecimal(fraction) {
|
65
|
+
const actualFraction = this.expandedFractionToSimple(fraction);
|
38
66
|
|
39
|
-
|
40
|
-
|
67
|
+
return actualFraction
|
68
|
+
.split('/')
|
69
|
+
.reduce((numerator, denominator, i) =>
|
70
|
+
numerator / (i ? denominator : 1)
|
71
|
+
);
|
72
|
+
}
|
73
|
+
expandedFractionToSimple(fraction){
|
74
|
+
if(fraction.includes(" ")){
|
75
|
+
factorSplit = fraction.split(" ");
|
76
|
+
factor = factorSplit[0];
|
77
|
+
|
78
|
+
fractionSplit = factorSplit[1].split("/");
|
79
|
+
numerator = fractionSplit[0];
|
80
|
+
denominator = fractionSplit[1];
|
81
|
+
|
82
|
+
return ((Number.parseInt(factor) * Number.parseInt(denominator)) + Number.parseInt(numerator)) + "/" + Number.parseInt(denominator);
|
83
|
+
}
|
84
|
+
return fraction;
|
85
|
+
}
|
41
86
|
|
42
|
-
return Math.floor(numerator) + '/' + Math.floor(denominator);
|
43
|
-
}
|
44
|
-
function gcd(a, b) {
|
45
|
-
if (b < 0.0000001) return a; // Since there is a limited precision we need to limit the value.
|
46
|
-
|
47
|
-
return gcd(b, Math.floor(a % b)); // Discard any fractions due to limitations in precision.
|
48
|
-
};
|
49
|
-
|
50
|
-
|
51
|
-
// from https://stackoverflow.com/a/49246271
|
52
|
-
function fractionToDecimal(fraction) {
|
53
|
-
return fraction
|
54
|
-
.split('/')
|
55
|
-
.reduce((numerator, denominator, i) =>
|
56
|
-
numerator / (i ? denominator : 1)
|
57
|
-
);
|
58
87
|
}
|
59
88
|
|
60
|
-
|
61
|
-
|
89
|
+
let ingredients = [];
|
90
|
+
// create a Ingredient Element for every HTML ELement
|
91
|
+
const ingredientHTMLElements = document.querySelectorAll('tr > td:first-child');
|
92
|
+
ingredientHTMLElements.forEach((ingredient) => ingredients.push(new Ingredient(ingredient.innerHTML, ingredient)));
|
93
|
+
|
94
|
+
|
95
|
+
const servingsInput = document.querySelector('input#servings_number');
|
96
|
+
var referenceServings = servingsInput.value;
|
97
|
+
|
98
|
+
/// react to servings input
|
99
|
+
servingsInput.addEventListener("change", calculateServings);
|
100
|
+
function calculateServings(){
|
101
|
+
const newPortion = servingsInput.value;
|
102
|
+
|
103
|
+
for (var i = 0; i < ingredients.length; i++) {
|
104
|
+
ingredients[i].calcAndRenderNewServingsValue(newPortion, referenceServings);
|
105
|
+
}
|
62
106
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-theme-recipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hanno Witzleb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
|
-
rubygems_version: 3.
|
187
|
+
rubygems_version: 3.4.6
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Recipe is a Jekyll theme for recipe websites, and adapted from CloudCannons
|