jekyll-timeago 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-timeago/core.rb +24 -36
- data/lib/jekyll-timeago/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e0b337ab84b9a0877f22bf5f4c442d6f44daace
|
4
|
+
data.tar.gz: c26bd56160a5effaf76a2968a96d9ee127ca4b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e78fdab222809a2afd8d64504418bc8e620663b7bd23adad641b6f8acab3c9c4e4e7028379a6419fae924a7b131bb44b3183262e5ae6c93d466acd07ec10953a
|
7
|
+
data.tar.gz: 3d7932fd4153e82fa8f47b817832d01054169c70102170e086d138d148b674fe96a493200098af41cb44c62cbf701751b561478386c1cbd1b5c8ccac7d4c9b27
|
data/lib/jekyll-timeago/core.rb
CHANGED
@@ -5,20 +5,10 @@ module Jekyll
|
|
5
5
|
module Core
|
6
6
|
extend self
|
7
7
|
|
8
|
-
|
9
|
-
days: 1,
|
10
|
-
weeks: 7,
|
11
|
-
months: 30,
|
12
|
-
years: 365
|
13
|
-
}
|
14
|
-
|
15
|
-
# Max level of detail
|
16
|
-
# years > months > weeks > days
|
17
|
-
# 1 year and 7 months and 2 weeks and 6 days
|
8
|
+
# Max level of detail: years > months > weeks > days
|
18
9
|
MAX_DEPTH_LEVEL = 4
|
19
10
|
|
20
11
|
# Default level of detail
|
21
|
-
# 1 month and 5 days, 3 weeks and 2 days, 2 years and 6 months
|
22
12
|
DEFAULT_DEPTH_LEVEL = 2
|
23
13
|
|
24
14
|
def timeago(from, to = Date.today, options = {})
|
@@ -46,7 +36,6 @@ module Jekyll
|
|
46
36
|
(1..MAX_DEPTH_LEVEL).include?(depth) ? depth : DEFAULT_DEPTH_LEVEL
|
47
37
|
end
|
48
38
|
|
49
|
-
# Days passed to time ago sentence
|
50
39
|
def time_ago_to_now(from, to, depth)
|
51
40
|
days_passed = (to - from).to_i
|
52
41
|
|
@@ -54,19 +43,14 @@ module Jekyll
|
|
54
43
|
return t(:yesterday) if days_passed == 1
|
55
44
|
return t(:tomorrow) if days_passed == -1
|
56
45
|
|
57
|
-
|
58
|
-
slots
|
59
|
-
sentence = to_sentence(slots)
|
46
|
+
past_or_future = from < to ? :past : :future
|
47
|
+
slots = build_time_ago_slots(days_passed.abs, depth)
|
60
48
|
|
61
|
-
|
62
|
-
t(:future, date_range: sentence)
|
63
|
-
else
|
64
|
-
t(:past, date_range: sentence)
|
65
|
-
end
|
49
|
+
t(past_or_future, date_range: to_sentence(slots))
|
66
50
|
end
|
67
51
|
|
68
52
|
def t(key, options = {})
|
69
|
-
MiniI18n.
|
53
|
+
MiniI18n.t(key, @options.merge(options))
|
70
54
|
end
|
71
55
|
|
72
56
|
# Builds time ranges: ['1 month', '5 days']
|
@@ -76,27 +60,31 @@ module Jekyll
|
|
76
60
|
def build_time_ago_slots(days_passed, depth, current_slots = [])
|
77
61
|
return current_slots if depth == 0 || days_passed == 0
|
78
62
|
|
79
|
-
|
80
|
-
days
|
81
|
-
num_elems
|
63
|
+
range = days_to_range(days_passed)
|
64
|
+
days = days_in(range)
|
65
|
+
num_elems = (days_passed / days).to_i
|
82
66
|
|
83
|
-
current_slots << t(
|
67
|
+
current_slots << t(range, count: num_elems)
|
84
68
|
|
85
69
|
pending_days = days_passed - (num_elems * days)
|
86
70
|
build_time_ago_slots(pending_days, depth - 1, current_slots)
|
87
71
|
end
|
88
72
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
when
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
73
|
+
def days_to_range(days)
|
74
|
+
case days.abs
|
75
|
+
when 1..6 then :days
|
76
|
+
when 7..30 then :weeks
|
77
|
+
when 31..365 then :months
|
78
|
+
else :years
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def days_in(range)
|
83
|
+
case range
|
84
|
+
when :days then 1
|
85
|
+
when :weeks then 7
|
86
|
+
when :months then 30
|
87
|
+
when :years then 365
|
100
88
|
end
|
101
89
|
end
|
102
90
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-timeago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_i18n
|