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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f57c4e0c53276d82a61f42b10703c7231c0bb6ab
4
- data.tar.gz: 4a3df430759408fe8838463d1264557e9080ec66
3
+ metadata.gz: 6e0b337ab84b9a0877f22bf5f4c442d6f44daace
4
+ data.tar.gz: c26bd56160a5effaf76a2968a96d9ee127ca4b86
5
5
  SHA512:
6
- metadata.gz: ed67ca75b17804ca091d0f41731cb526622653c3a9a363ce7a9d0edb507b4648fec872ff5b5effa067330b248a0e7cb5688c24d308a4de8751aea369e9606ee5
7
- data.tar.gz: db9204fdae404fd4e5ebb4f90ebd357cb18621e4f8275ffd147abefd32a008200d375996da4ea6fba82f42068fffbefa2a4ee149eb662fe8c5786bb77dd48e08
6
+ metadata.gz: e78fdab222809a2afd8d64504418bc8e620663b7bd23adad641b6f8acab3c9c4e4e7028379a6419fae924a7b131bb44b3183262e5ae6c93d466acd07ec10953a
7
+ data.tar.gz: 3d7932fd4153e82fa8f47b817832d01054169c70102170e086d138d148b674fe96a493200098af41cb44c62cbf701751b561478386c1cbd1b5c8ccac7d4c9b27
@@ -5,20 +5,10 @@ module Jekyll
5
5
  module Core
6
6
  extend self
7
7
 
8
- DAYS_PER = {
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
- future = days_passed < 0
58
- slots = build_time_ago_slots(days_passed.abs, depth)
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
- if future
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.translate(key, @options.merge(options))
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
- time_range = days_to_time_range(days_passed)
80
- days = DAYS_PER[time_range]
81
- num_elems = (days_passed / days).to_i
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(time_range, count: num_elems)
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
- # Number of days to minimum period time which can be grouped
90
- def days_to_time_range(days_passed)
91
- case days_passed.abs
92
- when 1..6
93
- :days
94
- when 7..30
95
- :weeks
96
- when 31..365
97
- :months
98
- else
99
- :years
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
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Timeago
3
- VERSION = "0.12.0"
3
+ VERSION = "0.12.1"
4
4
  end
5
5
  end
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.0
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-12 00:00:00.000000000 Z
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_i18n