jekyll-timeago 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/jekyll/timeago.rb +5 -2
- data/lib/jekyll/timeago/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Jekyll-Timeago
|
2
2
|
==============
|
3
|
-
Custom and simple implementation of `timeago` date filter. Futures and personalization
|
3
|
+
Custom and simple implementation of `timeago` date filter. Futures and personalization (level of detail) supported.
|
4
4
|
|
5
5
|
In fact, `jekyll-timeago` is an extension of [Liquid](https://github.com/Shopify/liquid) filters, so you can use it in all your Liquid templates.
|
6
6
|
|
@@ -54,6 +54,8 @@ Default behavior:
|
|
54
54
|
=> "tomorrow"
|
55
55
|
> timeago(Date.today + 7.days)
|
56
56
|
=> "in 1 week"
|
57
|
+
> timeago(Date.today + 1000.days)
|
58
|
+
=> "in 2 years and 8 months"
|
57
59
|
```
|
58
60
|
|
59
61
|
Change level of detail to get higher or lower granularity:
|
data/lib/jekyll/timeago.rb
CHANGED
@@ -40,7 +40,7 @@ module Jekyll
|
|
40
40
|
return "tomorrow" if days_passed == -1
|
41
41
|
|
42
42
|
future = days_passed < 0
|
43
|
-
slots = build_time_ago_slots(days_passed, depth)
|
43
|
+
slots = build_time_ago_slots(days_passed.abs, depth)
|
44
44
|
|
45
45
|
if future
|
46
46
|
"in #{slots.join(' and ')}"
|
@@ -50,12 +50,15 @@ module Jekyll
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# Builds time ranges: ['1 month', '5 days']
|
53
|
+
# - days_passed: integer in absolute
|
54
|
+
# - depth: level of detail
|
55
|
+
# - current_slots: slots built
|
53
56
|
def build_time_ago_slots(days_passed, depth, current_slots = [])
|
54
57
|
return current_slots if depth == 0 || days_passed == 0
|
55
58
|
|
56
59
|
time_range = days_to_time_range(days_passed)
|
57
60
|
days = DAYS_PER[time_range]
|
58
|
-
num_elems = days_passed
|
61
|
+
num_elems = days_passed / days
|
59
62
|
range_type = if num_elems == 1
|
60
63
|
time_range.to_s[0...-1] # singularize
|
61
64
|
else
|
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.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
72
|
version: '0'
|
73
73
|
segments:
|
74
74
|
- 0
|
75
|
-
hash:
|
75
|
+
hash: 811481889
|
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:
|
84
|
+
hash: 811481889
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
87
|
rubygems_version: 1.8.24
|