wordnik_ruby_helpers 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +11 -5
- data/lib/wordnik_ruby_helpers.rb +26 -9
- data/lib/wordnik_ruby_helpers/version.rb +1 -1
- data/spec/wordnik_ruby_helpers_spec.rb +35 -12
- data/wordnik_ruby_helpers.gemspec +7 -1
- metadata +24 -2
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wordnik_ruby_helpers (0.1.
|
4
|
+
wordnik_ruby_helpers (0.1.4)
|
5
5
|
RedCloth (>= 4.2.3)
|
6
6
|
rails
|
7
7
|
|
@@ -9,6 +9,7 @@ GEM
|
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
RedCloth (4.2.7)
|
12
|
+
ZenTest (4.5.0)
|
12
13
|
abstract (1.0.0)
|
13
14
|
actionmailer (3.0.7)
|
14
15
|
actionpack (= 3.0.7)
|
@@ -36,7 +37,10 @@ GEM
|
|
36
37
|
activemodel (= 3.0.7)
|
37
38
|
activesupport (= 3.0.7)
|
38
39
|
activesupport (3.0.7)
|
39
|
-
arel (2.0.
|
40
|
+
arel (2.0.10)
|
41
|
+
autotest (4.4.6)
|
42
|
+
ZenTest (>= 4.4.1)
|
43
|
+
autotest-rails-pure (4.1.2)
|
40
44
|
builder (2.1.2)
|
41
45
|
diff-lcs (1.1.2)
|
42
46
|
erubis (2.6.6)
|
@@ -49,7 +53,7 @@ GEM
|
|
49
53
|
treetop (~> 1.4.8)
|
50
54
|
mime-types (1.16)
|
51
55
|
polyglot (0.3.1)
|
52
|
-
rack (1.2.
|
56
|
+
rack (1.2.3)
|
53
57
|
rack-mount (0.6.14)
|
54
58
|
rack (>= 1.0.0)
|
55
59
|
rack-test (0.5.7)
|
@@ -67,7 +71,7 @@ GEM
|
|
67
71
|
activesupport (= 3.0.7)
|
68
72
|
rake (>= 0.8.7)
|
69
73
|
thor (~> 0.14.4)
|
70
|
-
rake (0.
|
74
|
+
rake (0.9.2)
|
71
75
|
rspec (2.5.0)
|
72
76
|
rspec-core (~> 2.5.0)
|
73
77
|
rspec-expectations (~> 2.5.0)
|
@@ -79,11 +83,13 @@ GEM
|
|
79
83
|
thor (0.14.6)
|
80
84
|
treetop (1.4.9)
|
81
85
|
polyglot (>= 0.3.1)
|
82
|
-
tzinfo (0.3.
|
86
|
+
tzinfo (0.3.29)
|
83
87
|
|
84
88
|
PLATFORMS
|
85
89
|
ruby
|
86
90
|
|
87
91
|
DEPENDENCIES
|
92
|
+
autotest
|
93
|
+
autotest-rails-pure
|
88
94
|
rspec
|
89
95
|
wordnik_ruby_helpers!
|
data/lib/wordnik_ruby_helpers.rb
CHANGED
@@ -18,18 +18,35 @@ module WordnikRubyHelpers
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# Use words if within the last week, otherwise use date (show year if not this year)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
# Good for SEO and humans.. see http://timeago.yarp.com
|
22
|
+
#
|
23
|
+
# Usage:
|
24
|
+
# timeago(Time.now)
|
25
|
+
# timeago(time, :relative_for => 30.days)
|
26
|
+
def timeago(time, *args)
|
27
|
+
time = Time.parse(time) unless time.class == Time
|
28
|
+
|
29
|
+
defaults = {
|
30
|
+
:relative_for => 1.week,
|
31
|
+
:title => time.getutc.iso8601,
|
32
|
+
:class => ""
|
33
|
+
}
|
34
|
+
options = defaults.merge(args.extract_options!)
|
35
|
+
|
36
|
+
# Add a 'relative' CSS class unless it's way old
|
37
|
+
if Time.now-time < options[:relative_for]
|
38
|
+
options[:class] = options[:class].to_s.squeeze(' ').split(' ').push('relative').join(' ')
|
30
39
|
end
|
40
|
+
|
41
|
+
# Take `relative_for` option out so it doesn't become an HTML attribute..
|
42
|
+
options.delete(:relative_for)
|
43
|
+
|
44
|
+
html_tag(:abbr, time.strftime('%b %e, %Y'), options)
|
31
45
|
end
|
32
46
|
|
47
|
+
# Legacy support..
|
48
|
+
alias :time_ago_in_words_or_date :timeago
|
49
|
+
|
33
50
|
# Output an easily styleable key-value pair
|
34
51
|
def info_pair(label, value)
|
35
52
|
value = content_tag(:span, "None", :class => "blank") if value.blank?
|
@@ -25,21 +25,44 @@ describe WordnikRubyHelpers do
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
-
context "
|
29
|
-
it "should get relative times right" do
|
30
|
-
time_ago_in_words_or_date(Time.now - 10.minutes).should == "10 minutes ago"
|
31
|
-
time_ago_in_words_or_date(Time.now - 1.day).should == "1 day ago"
|
32
|
-
time_ago_in_words_or_date(Time.now - 2.days).should == "2 days ago"
|
33
|
-
end
|
28
|
+
context "timeago" do
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
context "relative dates" do
|
31
|
+
|
32
|
+
it "returns nil if given bad input" do
|
33
|
+
expect { timeago("wonkalonka") }.to raise_error
|
34
|
+
expect { timeago(nil) }.to raise_error
|
35
|
+
expect { timeago(123) }.to raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it "supports legacy time_ago_in_words_or_date method name" do
|
39
|
+
timeago("05-07-2009 19:00").should be_a(String)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "accepts string input" do
|
43
|
+
timeago("05-07-2009 19:00").should be_a(String)
|
44
|
+
timeago("2006-12-24T17:58:58.000+0000").should be_a(String)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "uses a human-friendly format in the display text, eg. 'Dec 24, 2006'" do
|
48
|
+
timeago("2006-12-24T17:58:58.000+0000").should =~ /Dec 24, 2006/
|
49
|
+
end
|
50
|
+
|
51
|
+
it "renders an abbr tag" do
|
52
|
+
timeago(1.year.ago).should =~ /^\<abbr/
|
53
|
+
end
|
54
|
+
|
55
|
+
it "renders a title tag" do
|
56
|
+
timeago(1.year.ago).should =~ /title=/
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should render a css relative tag if within the last week" do
|
60
|
+
timeago(Time.now - 6.days).should =~ /class=\"relative\"/
|
61
|
+
timeago(Time.now - 8.days).should_not =~ /relative/
|
62
|
+
end
|
63
|
+
|
38
64
|
end
|
39
65
|
|
40
|
-
it "should display year format for non-relative dates beyond one year ago" do
|
41
|
-
time_ago_in_words_or_date(Time.now - 13.months).should =~ /\w{3} \d+, \d{4}/i
|
42
|
-
end
|
43
66
|
end
|
44
67
|
|
45
68
|
context "generate_table" do
|
@@ -18,7 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency 'RedCloth', '>= 4.2.3'
|
19
19
|
|
20
20
|
s.add_development_dependency 'rspec'
|
21
|
-
|
21
|
+
|
22
|
+
# Optional..
|
23
|
+
s.add_development_dependency 'autotest'
|
24
|
+
s.add_development_dependency 'autotest-rails-pure'
|
25
|
+
# s.add_development_dependency 'autotest-growl'
|
26
|
+
# s.add_development_dependency 'autotest-fsevent'
|
27
|
+
|
22
28
|
s.files = `git ls-files`.split("\n")
|
23
29
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
30
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wordnik_ruby_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Zeke Sikelianos
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-07-11 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,28 @@ dependencies:
|
|
47
47
|
version: "0"
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id003
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: autotest
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id004
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: autotest-rails-pure
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id005
|
50
72
|
description: A handful of monkey patches and view helpers that we use in our rails projects
|
51
73
|
email:
|
52
74
|
- zeke@wordnik.com
|