rails-timeago 2.0.0.beta1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +6 -2
- data/lib/rails-timeago.rb +18 -8
- data/lib/rails-timeago/helper.rb +3 -1
- data/lib/rails-timeago/version.rb +2 -2
- data/spec/timeago/helper_spec.rb +39 -4
- metadata +5 -5
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'rails-timeago', '~> 2.0
|
11
|
+
gem 'rails-timeago', '~> 2.0'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -64,6 +64,10 @@ Force time ago tag ignoring limit option.
|
|
64
64
|
String that will be returned if time is nil.
|
65
65
|
(default: '-')
|
66
66
|
|
67
|
+
**title**
|
68
|
+
A string or block that will be used to create a title attribute for timeago tags. It set to nil or false no title attribute will be set.
|
69
|
+
(default: proc { |time, options| I18n.l time, :format => options[:format] })
|
70
|
+
|
67
71
|
All other options will be given as options to the time tag helper.
|
68
72
|
The above options can be assigned globally as defaults using
|
69
73
|
|
@@ -104,7 +108,7 @@ Do not forget to require the needed locale files by either require `rails-timeag
|
|
104
108
|
|
105
109
|
Your customized jQuery locale files must be changed to work with **rails-timeago 2**. Instead of defining your locale strings as `jQuery.timeago.settings.strings` you need to define them like this:
|
106
110
|
|
107
|
-
jQuery.timeago.settings.
|
111
|
+
jQuery.timeago.settings.strings["en"] = {
|
108
112
|
...
|
109
113
|
}
|
110
114
|
|
data/lib/rails-timeago.rb
CHANGED
@@ -5,7 +5,7 @@ module Rails
|
|
5
5
|
module Timeago
|
6
6
|
if defined?(::Rails::Engine)
|
7
7
|
class Engine < ::Rails::Engine # :nodoc:
|
8
|
-
initializer 'rails-timeago', group
|
8
|
+
initializer 'rails-timeago', :group => :all do |app|
|
9
9
|
ActiveSupport.on_load(:action_controller) do
|
10
10
|
include Rails::Timeago::Helper
|
11
11
|
end
|
@@ -47,19 +47,29 @@ module Rails
|
|
47
47
|
# (default: '-')
|
48
48
|
#
|
49
49
|
def self.default_options(opts = nil)
|
50
|
-
@defaults ||=
|
50
|
+
@defaults ||= self.option_hash
|
51
|
+
if opts
|
52
|
+
@defaults.merge! opts.extract!(*@defaults.keys.select{|k| opts.include?(k)})
|
53
|
+
else
|
54
|
+
@defaults
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Reset options to default values
|
59
|
+
def self.reset_default_options
|
60
|
+
@defaults = self.option_hash
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.option_hash
|
64
|
+
{
|
51
65
|
:nojs => false,
|
52
66
|
:force => false,
|
53
67
|
:format => :default,
|
54
68
|
:limit => proc { 4.days.ago },
|
55
69
|
:date_only => true,
|
56
|
-
:default => '-'
|
70
|
+
:default => '-',
|
71
|
+
:title => proc { |time, options| I18n.l time, :format => options[:format] }
|
57
72
|
}
|
58
|
-
if opts
|
59
|
-
@defaults.merge! opts.extract!(*@defaults.keys.select{|k| opts.include?(k)})
|
60
|
-
else
|
61
|
-
@defaults
|
62
|
-
end
|
63
73
|
end
|
64
74
|
end
|
65
75
|
end
|
data/lib/rails-timeago/helper.rb
CHANGED
@@ -39,7 +39,9 @@ module Rails
|
|
39
39
|
time_options = time_options.merge html_options.extract!(*time_options.keys.select{|k| html_options.include?(k)})
|
40
40
|
return time_options[:default] if time.nil?
|
41
41
|
|
42
|
-
|
42
|
+
if time_options[:title]
|
43
|
+
html_options.merge! :title => time_options[:title].is_a?(Proc) ? time_options[:title].call(time, time_options) : time_options[:title]
|
44
|
+
end
|
43
45
|
time_options[:limit] = time_options[:limit].call if time_options[:limit].is_a?(Proc)
|
44
46
|
|
45
47
|
if time_options[:force] or time_options[:limit].nil? or time_options[:limit] < time
|
data/spec/timeago/helper_spec.rb
CHANGED
@@ -3,18 +3,53 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
3
3
|
|
4
4
|
describe Rails::Timeago::Helper do
|
5
5
|
before { @stub = TimeagoStub.new }
|
6
|
+
after { Rails::Timeago.reset_default_options }
|
7
|
+
let(:time) { Time.now }
|
6
8
|
|
7
9
|
context "#timeago_tag" do
|
8
10
|
it 'should create a time tag' do
|
9
|
-
@stub.timeago_tag(
|
11
|
+
@stub.timeago_tag(time).should =~ /<time.*>.*<\/time>/
|
10
12
|
end
|
11
13
|
|
12
14
|
it 'should have title attribute' do
|
13
|
-
@stub.timeago_tag(
|
15
|
+
@stub.timeago_tag(time).should =~ /<time.*title=".*".*>.*<\/time>/
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have human readable datetime as title attribute' do
|
19
|
+
@stub.timeago_tag(time).should include("title=\"#{I18n.l time}\"")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have human readable datetime as title attribute with given format' do
|
23
|
+
@stub.timeago_tag(time, :format => :short).should include("title=\"#{I18n.l time, :format => :short}\"")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have human readable datetime as title attribute with global format' do
|
27
|
+
Rails::Timeago.default_options :format => :short
|
28
|
+
@stub.timeago_tag(time).should include("title=\"#{I18n.l time, :format => :short}\"")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have no title attribute if title is set to false globally' do
|
32
|
+
Rails::Timeago.default_options :title => false
|
33
|
+
@stub.timeago_tag(time).should_not =~ /<time.*title=".*".*>.*<\/time>/
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have no title attribute if title is set to nil globally' do
|
37
|
+
Rails::Timeago.default_options :title => nil
|
38
|
+
@stub.timeago_tag(time).should_not =~ /<time.*title=".*".*>.*<\/time>/
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should have title attribute with proc value globally' do
|
42
|
+
Rails::Timeago.default_options :title => proc { |time, options| options[:format] }
|
43
|
+
@stub.timeago_tag(time, :format => :short).should =~ /<time.*title="short".*>.*<\/time>/
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should have title attribute with proc value locally' do
|
47
|
+
@stub.timeago_tag(time, :format => :long,
|
48
|
+
:title => proc { |time, options| options[:format] }).should =~ /<time.*title="long".*>.*<\/time>/
|
14
49
|
end
|
15
50
|
|
16
51
|
it 'should have data-time-ago attribute' do
|
17
|
-
@stub.timeago_tag(
|
52
|
+
@stub.timeago_tag(time).should =~ /<time.*data-time-ago=".*".*>.*<\/time>/
|
18
53
|
end
|
19
54
|
|
20
55
|
it 'should not have data-time-ago attribute for times before limit' do
|
@@ -58,7 +93,7 @@ describe Rails::Timeago::Helper do
|
|
58
93
|
end
|
59
94
|
|
60
95
|
it 'should pass html option to tag helper' do
|
61
|
-
@stub.timeago_tag(
|
96
|
+
@stub.timeago_tag(time, :myattr => 'abc').should =~ /<time.*myattr="abc".*>.*<\/time>/
|
62
97
|
end
|
63
98
|
|
64
99
|
it "should allow to set global options" do
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-timeago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jan Graichen
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -132,9 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
none: false
|
134
134
|
requirements:
|
135
|
-
- - ! '
|
135
|
+
- - ! '>='
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
137
|
+
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
140
|
rubygems_version: 1.8.24
|