jekyll-timeago 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -63,9 +63,9 @@ Change level of detail to get higher or lower granularity:
63
63
  > timeago(Date.today - 500.days) # default
64
64
  => "1 year ago and 4 months ago"
65
65
  > timeago(Date.today - 500.days, 3)
66
- => "1 year and 4 months and 1 week ago"
66
+ => "1 year, 4 months and 1 week ago"
67
67
  > timeago(Date.today - 500.days, 4)
68
- => "1 year and 4 months and 1 week and 4 days ago"
68
+ => "1 year, 4 months, 1 week and 4 days ago"
69
69
  > timeago(Date.today - 500.days, 1)
70
70
  => "1 year ago"
71
71
  ```
@@ -34,25 +34,27 @@ module Jekyll
34
34
 
35
35
  private
36
36
 
37
+ # Days passed to time ago sentence
37
38
  def time_ago_to_now(days_passed, depth)
38
39
  return "today" if days_passed == 0
39
40
  return "yesterday" if days_passed == 1
40
41
  return "tomorrow" if days_passed == -1
41
42
 
42
- future = days_passed < 0
43
- slots = build_time_ago_slots(days_passed.abs, depth)
43
+ future = days_passed < 0
44
+ slots = build_time_ago_slots(days_passed.abs, depth)
45
+ sentence = to_sentence(slots)
44
46
 
45
47
  if future
46
- "in #{slots.join(' and ')}"
48
+ "in #{sentence}"
47
49
  else
48
- "#{slots.join(' and ')} ago"
50
+ "#{sentence} ago"
49
51
  end
50
52
  end
51
53
 
52
54
  # Builds time ranges: ['1 month', '5 days']
53
55
  # - days_passed: integer in absolute
54
56
  # - depth: level of detail
55
- # - current_slots: slots built
57
+ # - current_slots: built time slots
56
58
  def build_time_ago_slots(days_passed, depth, current_slots = [])
57
59
  return current_slots if depth == 0 || days_passed == 0
58
60
 
@@ -70,6 +72,7 @@ module Jekyll
70
72
  build_time_ago_slots(pending_days, depth - 1, current_slots)
71
73
  end
72
74
 
75
+ # Number of days to minimum period time which can be grouped
73
76
  def days_to_time_range(days_passed)
74
77
  case days_passed.abs
75
78
  when 0...7
@@ -83,9 +86,19 @@ module Jekyll
83
86
  end
84
87
  end
85
88
 
89
+ # Validate if allowed level of detail
86
90
  def depth_allowed?(depth)
87
91
  (1..MAX_DEPTH_LEVEL).include?(depth)
88
92
  end
93
+
94
+ # Array to sentence: ['1 month', '1 week', '5 days'] => "1 month, 1 week and 5 days"
95
+ def to_sentence(slots)
96
+ if slots.length == 1
97
+ slots[0]
98
+ else
99
+ "#{slots[0...-1].join(', ')} and #{slots[-1]}"
100
+ end
101
+ end
89
102
  end
90
103
  end
91
104
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Timeago
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-timeago
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-06 00:00:00.000000000 Z
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
72
  version: '0'
73
73
  segments:
74
74
  - 0
75
- hash: 811481889
75
+ hash: 1046143283
76
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  none: false
78
78
  requirements:
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  segments:
83
83
  - 0
84
- hash: 811481889
84
+ hash: 1046143283
85
85
  requirements: []
86
86
  rubyforge_project:
87
87
  rubygems_version: 1.8.24