jekyll-timeago 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Jekyll-Timeago
2
2
  ==============
3
- Custom and simple implementation of `timeago` date filter.
3
+ Custom and simple implementation of `timeago` date filter. Futures supported.
4
4
 
5
5
  ## Installation
6
6
  Add this gem to your Gemfile and run bundle:
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["srmarc.ai@gmail.com"]
11
11
  spec.description = %q{Custom timeago filter for Jekyll}
12
12
  spec.summary = %q{Custom timeago filter for Jekyll}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/markets/jekyll-timeago"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_dependency "activesupport"
23
24
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Timeago
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,7 +1,16 @@
1
1
  require "jekyll/timeago/version"
2
+ require "active_support/inflector"
2
3
 
3
4
  module Jekyll
4
5
  module Timeago
6
+
7
+ DAYS_IN = {
8
+ :days => 1,
9
+ :weeks => 7,
10
+ :months => 31,
11
+ :years => 365,
12
+ }
13
+
5
14
  def timeago(input)
6
15
  time_ago_to_now(input)
7
16
  end
@@ -11,19 +20,36 @@ module Jekyll
11
20
  def time_ago_to_now(date)
12
21
  days_passed = (Date.today - Date.parse(date.to_s)).to_i
13
22
 
14
- case days_passed
23
+ case days_passed.abs
15
24
  when 0
16
25
  'today'
17
- when 1
18
- 'yesterday'
19
- when 2 .. 7
20
- "#{days_passed} days ago"
26
+ when 1 .. 7
27
+ time_ago_to_s(days_passed, :days)
21
28
  when 8 .. 31
22
- "#{days_passed/7} weeks ago"
29
+ time_ago_to_s(days_passed, :weeks)
23
30
  when 32 .. 365
24
- "#{days_passed/31} months ago"
31
+ time_ago_to_s(days_passed, :months)
32
+ else
33
+ time_ago_to_s(days_passed, :years)
34
+ end
35
+ end
36
+
37
+ def time_ago_to_s(days_passed, grouped_by)
38
+ return "yesterday" if days_passed == 1
39
+ return "tomorrow" if days_passed == -1
40
+
41
+ future = days_passed < 0
42
+ computed_range = days_passed.abs / Jekyll::Timeago::DAYS_IN[grouped_by]
43
+ grouped_by = if computed_range == 1
44
+ ActiveSupport::Inflector.singularize(grouped_by.to_s)
45
+ else
46
+ grouped_by.to_s
47
+ end
48
+
49
+ if future
50
+ "in #{computed_range} #{grouped_by}"
25
51
  else
26
- "#{days_passed/365} years ago"
52
+ "#{computed_range} #{grouped_by} ago"
27
53
  end
28
54
  end
29
55
  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.0.1
4
+ version: 0.1.0
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-06-12 00:00:00.000000000 Z
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: Custom timeago filter for Jekyll
47
63
  email:
48
64
  - srmarc.ai@gmail.com
@@ -57,7 +73,7 @@ files:
57
73
  - jekyll-timeago.gemspec
58
74
  - lib/jekyll/timeago.rb
59
75
  - lib/jekyll/timeago/version.rb
60
- homepage: ''
76
+ homepage: https://github.com/markets/jekyll-timeago
61
77
  licenses:
62
78
  - MIT
63
79
  post_install_message:
@@ -72,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
88
  version: '0'
73
89
  segments:
74
90
  - 0
75
- hash: 381834157
91
+ hash: -419869265
76
92
  required_rubygems_version: !ruby/object:Gem::Requirement
77
93
  none: false
78
94
  requirements:
@@ -81,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
97
  version: '0'
82
98
  segments:
83
99
  - 0
84
- hash: 381834157
100
+ hash: -419869265
85
101
  requirements: []
86
102
  rubyforge_project:
87
103
  rubygems_version: 1.8.24