rails-timeago 2.14.0 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +53 -0
- data/.travis.yml +7 -9
- data/CHANGELOG.md +26 -0
- data/Gemfile +9 -2
- data/README.md +12 -14
- data/Rakefile +14 -12
- data/lib/assets/javascripts/rails-timeago-all.js +8 -0
- data/lib/assets/javascripts/rails-timeago.js +4 -2
- data/lib/rails-timeago.rb +21 -17
- data/lib/rails-timeago/helper.rb +13 -10
- data/lib/rails-timeago/version.rb +3 -1
- data/rails-timeago.gemspec +13 -12
- data/spec/rails-timeago_spec.rb +46 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/assets/javascripts/jquery.js +4 -0
- data/spec/support/stub.rb +75 -4
- data/spec/timeago/helper_spec.rb +157 -110
- data/vendor/assets/javascripts/jquery.timeago.js +14 -7
- data/vendor/assets/javascripts/locales/jquery.timeago.af.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.am.js +30 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.ar.js +13 -5
- data/vendor/assets/javascripts/locales/jquery.timeago.az-short.js +30 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.az.js +30 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.be.js +43 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.bg.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.bs.js +13 -7
- data/vendor/assets/javascripts/locales/jquery.timeago.ca.js +30 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.cs.js +34 -24
- data/vendor/assets/javascripts/locales/jquery.timeago.cy.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.da.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.de-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.de.js +29 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.dv.js +32 -22
- data/vendor/assets/javascripts/locales/jquery.timeago.el.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.en-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.eo.js +30 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.es-short.js +31 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.es.js +29 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.et.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.eu.js +28 -17
- data/vendor/assets/javascripts/locales/jquery.timeago.fa-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.fa.js +32 -22
- data/vendor/assets/javascripts/locales/jquery.timeago.fi.js +38 -28
- data/vendor/assets/javascripts/locales/jquery.timeago.fr-short.js +26 -16
- data/vendor/assets/javascripts/locales/jquery.timeago.fr.js +27 -17
- data/vendor/assets/javascripts/locales/jquery.timeago.gl.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.he.js +26 -16
- data/vendor/assets/javascripts/locales/jquery.timeago.hr.js +53 -48
- data/vendor/assets/javascripts/locales/jquery.timeago.hu.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.hy.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.id.js +29 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.is.js +29 -19
- data/vendor/assets/javascripts/locales/jquery.timeago.it-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.it.js +28 -16
- data/vendor/assets/javascripts/locales/jquery.timeago.ja.js +29 -19
- data/vendor/assets/javascripts/locales/jquery.timeago.jv.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.ka.js +30 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.ko.js +31 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.ky.js +12 -4
- data/vendor/assets/javascripts/locales/jquery.timeago.lt.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.lv.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.mk.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.nl.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.no.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.pl.js +11 -3
- data/vendor/assets/javascripts/locales/jquery.timeago.pt-br-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.pt-br.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.pt-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.pt.js +26 -16
- data/vendor/assets/javascripts/locales/jquery.timeago.ro.js +29 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.rs.js +53 -48
- data/vendor/assets/javascripts/locales/jquery.timeago.ru.js +14 -5
- data/vendor/assets/javascripts/locales/jquery.timeago.rw.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.si.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.sk.js +34 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.sl.js +45 -39
- data/vendor/assets/javascripts/locales/jquery.timeago.sq.js +26 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.sr.js +53 -48
- data/vendor/assets/javascripts/locales/jquery.timeago.sv.js +28 -18
- data/vendor/assets/javascripts/locales/jquery.timeago.th.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.tr-short.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.tr.js +26 -16
- data/vendor/assets/javascripts/locales/jquery.timeago.uk.js +12 -4
- data/vendor/assets/javascripts/locales/jquery.timeago.ur.js +30 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.uz.js +29 -19
- data/vendor/assets/javascripts/locales/jquery.timeago.vi.js +30 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.zh-CN.js +31 -20
- data/vendor/assets/javascripts/locales/jquery.timeago.zh-TW.js +30 -20
- metadata +14 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5653983cf12f0fdc7e6a9652e32a0b416c7df3467e10c94e7cffb4a89d7bd46b
|
4
|
+
data.tar.gz: 48da15e4a1f7b9d6a9ddbc05574927d560f92eea17b9e578139f9ed17c142f59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9240a67ff85cf0d11264efcfed29846f988a164a45fca5a576e52d94eba0a6d67fe1ce6c63b0bd1d9ea42d856818573036ccfb6fdca0e0bb5c8ed63aaf35e1d5
|
7
|
+
data.tar.gz: 7103a15660b81043bdd7a1e1b0aeda93c94ae5c43098b3376794dd86dea26ec96aaf9201091b15d662baa394eee792e4a0ad29f37c7134acdf9f882809d8dfb7
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- '**/*.rb'
|
4
|
+
TargetRubyVersion: 2.1
|
5
|
+
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Exclude:
|
8
|
+
- 'spec/**/*_spec.rb'
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/**/*_spec.rb'
|
13
|
+
|
14
|
+
Style/AlignParameters:
|
15
|
+
EnforcedStyle: with_fixed_indentation
|
16
|
+
|
17
|
+
Style/BracesAroundHashParameters:
|
18
|
+
EnforcedStyle: context_dependent
|
19
|
+
|
20
|
+
Style/SpaceInsideHashLiteralBraces:
|
21
|
+
EnforcedStyle: no_space
|
22
|
+
|
23
|
+
Style/RaiseArgs:
|
24
|
+
EnforcedStyle: compact
|
25
|
+
|
26
|
+
Style/Documentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/SpaceInsideBlockBraces:
|
30
|
+
EnforcedStyle: space
|
31
|
+
EnforcedStyleForEmptyBraces: no_space
|
32
|
+
SpaceBeforeBlockParameters: false
|
33
|
+
|
34
|
+
Style/SignalException:
|
35
|
+
EnforcedStyle: only_raise
|
36
|
+
|
37
|
+
Style/CaseIndentation:
|
38
|
+
EnforcedStyle: end
|
39
|
+
SupportedStyles:
|
40
|
+
- case
|
41
|
+
- end
|
42
|
+
IndentOneStep: true
|
43
|
+
|
44
|
+
Style/ClassAndModuleChildren:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/TrivialAccessors:
|
48
|
+
AllowPredicates: true
|
49
|
+
|
50
|
+
Style/FileName:
|
51
|
+
Exclude:
|
52
|
+
- Rakefile
|
53
|
+
- Gemfile
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.19.0
|
4
|
+
|
5
|
+
* Update jquery-timeago and locales from upstream
|
6
|
+
* Reinitialize on ajaxSuccess event too (#34)
|
7
|
+
|
8
|
+
## 2.18.0
|
9
|
+
|
10
|
+
* Update jquery-timeago and locales from upstream
|
11
|
+
|
12
|
+
## 2.17.1
|
13
|
+
|
14
|
+
* Maintenance release without code changes
|
15
|
+
|
16
|
+
## 2.17.0
|
17
|
+
|
18
|
+
* Update jquery-timeago and locales from upstream
|
19
|
+
|
20
|
+
## 2.16.0
|
21
|
+
|
22
|
+
* Update jquery-timeago and locales from upstream
|
23
|
+
|
24
|
+
## 2.15.0
|
25
|
+
|
26
|
+
* Update jquery-timeago and locales from upstream
|
27
|
+
* Remove an use of deprecated "ready" event (compatible with jQuery 3.0) (#40)
|
28
|
+
|
3
29
|
## 2.14.0
|
4
30
|
|
5
31
|
* Update jquery-timeago and locales from upstream
|
data/Gemfile
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in rails-timeago.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
8
|
group :development do
|
7
|
-
gem
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rake-release'
|
8
11
|
end
|
9
12
|
|
10
|
-
|
13
|
+
group :test do
|
14
|
+
gem 'capybara', '~> 3.14'
|
15
|
+
gem 'poltergeist', '~> 1.10'
|
16
|
+
gem 'rspec', '~> 3.5'
|
17
|
+
end
|
data/README.md
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# rails-timeago
|
2
2
|
|
3
|
-
[![Gem Version](https://
|
4
|
-
[![Build Status](https://
|
5
|
-
[![Code Climate](https://codeclimate.com/github/jgraichen/rails-timeago.svg)](https://codeclimate.com/github/jgraichen/rails-timeago)
|
6
|
-
[![Dependency Status](https://gemnasium.com/jgraichen/rails-timeago.svg)](https://gemnasium.com/jgraichen/rails-timeago)
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/rails-timeago?logo=ruby)](https://rubygems.org/gems/rails-timeago)
|
4
|
+
[![Build Status](https://img.shields.io/travis/jgraichen/rails-timeago/master?logo=travis)](https://travis-ci.org/jgraichen/rails-timeago)
|
7
5
|
|
8
6
|
**rails-timeago** provides a timeago_tag helper to create time tags usable for
|
9
7
|
[jQuery Timeago](https://github.com/rmm5t/jquery-timeago) plugin.
|
@@ -34,21 +32,23 @@ Use the following to also include all available locale files:
|
|
34
32
|
|
35
33
|
//= require rails-timeago-all
|
36
34
|
|
35
|
+
If using a recent Rails with `rails-ujs`, jQuery might not be present anymore. You need to add `jquery-rails` to your `Gemfile` and load it, e.g.:
|
36
|
+
|
37
|
+
//= require jquery
|
38
|
+
//= require rails-timeago
|
39
|
+
//= require rails-timeago-all
|
40
|
+
|
37
41
|
## Usage
|
38
42
|
|
39
43
|
Use the timeago_tag helper like any other regular tag helper:
|
40
44
|
|
41
45
|
```erb
|
42
|
-
<%= timeago_tag Time.zone.now
|
46
|
+
<%= timeago_tag Time.zone.now limit: 10.days.ago %>
|
43
47
|
```
|
44
48
|
|
45
49
|
|
46
50
|
### Available options:
|
47
51
|
|
48
|
-
**nojs**
|
49
|
-
Add time ago in words as time tag content instead of absolute time.
|
50
|
-
(default: `false`)
|
51
|
-
|
52
52
|
**date_only**
|
53
53
|
Only print date as tag content instead of full time.
|
54
54
|
(default: `true`)
|
@@ -71,13 +71,13 @@ String that will be returned if time is `nil`.
|
|
71
71
|
|
72
72
|
**title**
|
73
73
|
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.
|
74
|
-
(default: `proc { |time, options| I18n.l time, :
|
74
|
+
(default: `proc { |time, options| I18n.l time, format: options[:format] }`)
|
75
75
|
|
76
76
|
All other options will be given as options to the time tag helper.
|
77
77
|
The above options can be assigned globally as defaults using
|
78
78
|
|
79
79
|
```ruby
|
80
|
-
Rails::Timeago.default_options :
|
80
|
+
Rails::Timeago.default_options limit: proc { 20.days.ago }
|
81
81
|
```
|
82
82
|
|
83
83
|
A global limit should always be given as a block that will be evaluated each time the rails `timeago_tag` helper is called. That avoids the limit becoming smaller the longer the application runs.
|
@@ -87,7 +87,7 @@ A global limit should always be given as a block that will be evaluated each tim
|
|
87
87
|
**rails-timeago 2** ships with a modified version of jQuery timeago that allows to include all locale files at once and set the locale via an option or per element via the `lang` attribute:
|
88
88
|
|
89
89
|
```erb
|
90
|
-
<%= timeago_tag Time.zone.now, :
|
90
|
+
<%= timeago_tag Time.zone.now, lang: :de %>
|
91
91
|
```
|
92
92
|
|
93
93
|
The following snippet will print a script tag that set the jQuery timeago locale according to your `I18n.locale`:
|
@@ -113,8 +113,6 @@ Do not forget to require the needed locale files by either require `rails-timeag
|
|
113
113
|
|
114
114
|
**rails-timeago** includes locale files for the following locales taken from [jQuery Timeago](https://github.com/rmm5t/jquery-timeago).
|
115
115
|
|
116
|
-
> de cy pl mk zh-CN bs en-short it fi es uk lt zh-TW sk hy ca pt el sv ar no fa fr pt-br tr he bg ko uz cz sl hu id hr ru nl fr-short da ja ro th
|
117
|
-
|
118
116
|
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:
|
119
117
|
|
120
118
|
```js
|
data/Rakefile
CHANGED
@@ -1,45 +1,47 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'rake/release'
|
3
5
|
require 'rspec/core/rake_task'
|
4
6
|
|
5
7
|
RSpec::Core::RakeTask.new(:spec)
|
6
8
|
|
7
|
-
task :
|
9
|
+
task default: :spec
|
8
10
|
|
9
11
|
desc 'Update jquery-timeago from upstream'
|
10
12
|
task :update do
|
11
|
-
puts
|
13
|
+
puts 'Clone repository..'
|
12
14
|
puts `mkdir ./tmp`
|
13
15
|
puts `git clone https://github.com/rmm5t/jquery-timeago.git ./tmp`
|
14
16
|
|
15
|
-
puts
|
17
|
+
puts 'Patch jquery timeago...'
|
16
18
|
puts `cd ./tmp && patch -p1 < ../scripts/jquery.timeago.js.patch`
|
17
19
|
|
18
20
|
print 'Patch locale files ... '
|
19
21
|
`rm ./tmp/locales/jquery.timeago.en.js`
|
20
22
|
|
21
|
-
is_mac = RUBY_PLATFORM.downcase.include?(
|
23
|
+
is_mac = RUBY_PLATFORM.downcase.include?('darwin')
|
22
24
|
|
23
|
-
Dir[
|
25
|
+
Dir['./tmp/locales/*.js'].each do |file|
|
24
26
|
if file =~ /jquery\.timeago\.(.+)\.js$/
|
25
|
-
`sed -i#{
|
26
|
-
print "#{
|
27
|
+
`sed -i#{is_mac ? " ''" : nil} "s/timeago.settings.strings/timeago.settings.strings[\\"#{Regexp.last_match(1)}\\"]/" #{file}`
|
28
|
+
print "#{Regexp.last_match(1)} "
|
27
29
|
end
|
28
30
|
end
|
29
31
|
puts
|
30
32
|
|
31
|
-
puts
|
33
|
+
puts 'Copying asset files...'
|
32
34
|
puts `cp ./tmp/jquery.timeago.js ./vendor/assets/javascripts/`
|
33
35
|
puts `rm ./vendor/assets/javascripts/locales/*`
|
34
36
|
puts `cp ./tmp/locales/*.js ./vendor/assets/javascripts/locales`
|
35
37
|
|
36
|
-
puts
|
38
|
+
puts 'Generate rails-timeago-all.js...'
|
37
39
|
`echo "// Rails timeago bootstrap with all locales" > ./lib/assets/javascripts/rails-timeago-all.js`
|
38
40
|
`echo "//= require rails-timeago" >> ./lib/assets/javascripts/rails-timeago-all.js`
|
39
|
-
Dir[
|
41
|
+
Dir['./vendor/assets/javascripts/locales/*.js'].sort.each do |file|
|
40
42
|
`echo "//= require locales/#{File.basename(file)}" >> ./lib/assets/javascripts/rails-timeago-all.js`
|
41
43
|
end
|
42
44
|
|
43
|
-
puts
|
45
|
+
puts 'Clean up...'
|
44
46
|
puts `rm -rf ./tmp`
|
45
47
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
// Rails timeago bootstrap with all locales
|
2
2
|
//= require rails-timeago
|
3
3
|
//= require locales/jquery.timeago.af.js
|
4
|
+
//= require locales/jquery.timeago.am.js
|
4
5
|
//= require locales/jquery.timeago.ar.js
|
6
|
+
//= require locales/jquery.timeago.az-short.js
|
7
|
+
//= require locales/jquery.timeago.az.js
|
8
|
+
//= require locales/jquery.timeago.be.js
|
5
9
|
//= require locales/jquery.timeago.bg.js
|
6
10
|
//= require locales/jquery.timeago.bs.js
|
7
11
|
//= require locales/jquery.timeago.ca.js
|
@@ -13,6 +17,7 @@
|
|
13
17
|
//= require locales/jquery.timeago.dv.js
|
14
18
|
//= require locales/jquery.timeago.el.js
|
15
19
|
//= require locales/jquery.timeago.en-short.js
|
20
|
+
//= require locales/jquery.timeago.eo.js
|
16
21
|
//= require locales/jquery.timeago.es-short.js
|
17
22
|
//= require locales/jquery.timeago.es.js
|
18
23
|
//= require locales/jquery.timeago.et.js
|
@@ -33,6 +38,7 @@
|
|
33
38
|
//= require locales/jquery.timeago.it.js
|
34
39
|
//= require locales/jquery.timeago.ja.js
|
35
40
|
//= require locales/jquery.timeago.jv.js
|
41
|
+
//= require locales/jquery.timeago.ka.js
|
36
42
|
//= require locales/jquery.timeago.ko.js
|
37
43
|
//= require locales/jquery.timeago.ky.js
|
38
44
|
//= require locales/jquery.timeago.lt.js
|
@@ -52,12 +58,14 @@
|
|
52
58
|
//= require locales/jquery.timeago.si.js
|
53
59
|
//= require locales/jquery.timeago.sk.js
|
54
60
|
//= require locales/jquery.timeago.sl.js
|
61
|
+
//= require locales/jquery.timeago.sq.js
|
55
62
|
//= require locales/jquery.timeago.sr.js
|
56
63
|
//= require locales/jquery.timeago.sv.js
|
57
64
|
//= require locales/jquery.timeago.th.js
|
58
65
|
//= require locales/jquery.timeago.tr-short.js
|
59
66
|
//= require locales/jquery.timeago.tr.js
|
60
67
|
//= require locales/jquery.timeago.uk.js
|
68
|
+
//= require locales/jquery.timeago.ur.js
|
61
69
|
//= require locales/jquery.timeago.uz.js
|
62
70
|
//= require locales/jquery.timeago.vi.js
|
63
71
|
//= require locales/jquery.timeago.zh-CN.js
|
@@ -4,7 +4,9 @@
|
|
4
4
|
//= require jquery.timeago
|
5
5
|
|
6
6
|
(function($) {
|
7
|
-
|
7
|
+
var fn = function() {
|
8
8
|
$('time[data-time-ago]').timeago();
|
9
|
-
}
|
9
|
+
};
|
10
|
+
$(fn);
|
11
|
+
$(document).on('turbolinks:load page:load ajax:success ajaxSuccess', fn);
|
10
12
|
})(jQuery);
|
data/lib/rails-timeago.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails-timeago/version'
|
4
|
+
require 'rails-timeago/helper'
|
3
5
|
|
4
6
|
module Rails
|
5
7
|
module Timeago
|
6
8
|
if defined?(::Rails::Engine)
|
7
9
|
class Engine < ::Rails::Engine # :nodoc:
|
8
|
-
initializer 'rails-timeago', :
|
10
|
+
initializer 'rails-timeago', group: :all do |_app|
|
9
11
|
ActiveSupport.on_load(:action_controller) do
|
10
12
|
include Rails::Timeago::Helper
|
11
13
|
end
|
@@ -17,8 +19,8 @@ module Rails
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
# Read or write global rails-timeago default options. If no options are
|
21
|
-
# the current defaults will be returned.
|
22
|
+
# Read or write global rails-timeago default options. If no options are
|
23
|
+
# given the current defaults will be returned.
|
22
24
|
#
|
23
25
|
# Available options:
|
24
26
|
# [:+nojs+]
|
@@ -34,8 +36,9 @@ module Rails
|
|
34
36
|
# (default: :default)
|
35
37
|
#
|
36
38
|
# [:+limit+]
|
37
|
-
# Set a limit for time ago tags. All dates before given limit will not
|
38
|
-
# Global limit should be given as a block to reevaluate
|
39
|
+
# Set a limit for time ago tags. All dates before given limit will not
|
40
|
+
# be converted. Global limit should be given as a block to reevaluate
|
41
|
+
# limit each time timeago_tag is called.
|
39
42
|
# (default: proc { 4.days.ago })
|
40
43
|
#
|
41
44
|
# [:+force+]
|
@@ -47,9 +50,10 @@ module Rails
|
|
47
50
|
# (default: '-')
|
48
51
|
#
|
49
52
|
def self.default_options(opts = nil)
|
50
|
-
@defaults ||=
|
53
|
+
@defaults ||= option_hash
|
51
54
|
if opts
|
52
|
-
@defaults.merge!
|
55
|
+
@defaults.merge! \
|
56
|
+
opts.extract!(*@defaults.keys.select {|k| opts.include?(k) })
|
53
57
|
else
|
54
58
|
@defaults
|
55
59
|
end
|
@@ -57,18 +61,18 @@ module Rails
|
|
57
61
|
|
58
62
|
# Reset options to default values
|
59
63
|
def self.reset_default_options
|
60
|
-
@defaults =
|
64
|
+
@defaults = option_hash
|
61
65
|
end
|
62
66
|
|
63
67
|
def self.option_hash
|
64
68
|
{
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
69
|
+
nojs: false,
|
70
|
+
force: false,
|
71
|
+
format: :default,
|
72
|
+
limit: proc { 4.days.ago },
|
73
|
+
date_only: true,
|
74
|
+
default: '-',
|
75
|
+
title: proc {|time, options| I18n.l time, format: options[:format] }
|
72
76
|
}
|
73
77
|
end
|
74
78
|
end
|
data/lib/rails-timeago/helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/time'
|
2
4
|
|
3
5
|
module Rails
|
@@ -6,7 +8,9 @@ module Rails
|
|
6
8
|
# Create a time tag usable for jQuery timeago plugin.
|
7
9
|
#
|
8
10
|
# timeago_tag Time.zone.now
|
9
|
-
# => "<time datetime="2012-03-10T12:07:07+01:00"
|
11
|
+
# => "<time datetime="2012-03-10T12:07:07+01:00"
|
12
|
+
# title="Sat, 10 Mar 2012 12:07:07 +0100"
|
13
|
+
# data-time-ago="2012-03-10T12:07:07+01:00">2012-03-10</time>"
|
10
14
|
#
|
11
15
|
# Available options:
|
12
16
|
# [:+nojs+]
|
@@ -22,7 +26,8 @@ module Rails
|
|
22
26
|
# (default: :default)
|
23
27
|
#
|
24
28
|
# [:+limit+]
|
25
|
-
# Set a limit for time ago tags. All dates before given limit
|
29
|
+
# Set a limit for time ago tags. All dates before given limit
|
30
|
+
# will not be converted.
|
26
31
|
# (default: 4.days.ago)
|
27
32
|
#
|
28
33
|
# [:+force+]
|
@@ -38,12 +43,12 @@ module Rails
|
|
38
43
|
def timeago_tag(time, html_options = {})
|
39
44
|
time_options = Rails::Timeago.default_options
|
40
45
|
|
41
|
-
time_options = time_options.merge html_options.extract!(*time_options.keys.select{|k| html_options.include?(k)})
|
46
|
+
time_options = time_options.merge html_options.extract!(*time_options.keys.select {|k| html_options.include?(k) })
|
42
47
|
return time_options[:default] if time.nil?
|
43
48
|
|
44
49
|
time_options[:format] = time_options[:format].call(time, time_options) if time_options[:format].is_a?(Proc)
|
45
50
|
if time_options[:title]
|
46
|
-
html_options
|
51
|
+
html_options[:title] = time_options[:title].is_a?(Proc) ? time_options[:title].call(time, time_options) : time_options[:title]
|
47
52
|
end
|
48
53
|
time_options[:limit] = time_options[:limit].call if time_options[:limit].is_a?(Proc)
|
49
54
|
|
@@ -51,21 +56,19 @@ module Rails
|
|
51
56
|
now = Time.zone.now
|
52
57
|
limit = time_options[:limit]
|
53
58
|
limit < now ? limit...now : now...limit
|
54
|
-
else
|
55
|
-
nil
|
56
59
|
end
|
57
60
|
|
58
|
-
if time_options[:force]
|
59
|
-
html_options
|
61
|
+
if time_options[:force] || time_range.nil? || time_range.cover?(time)
|
62
|
+
html_options['data-time-ago'] = time.iso8601
|
60
63
|
end
|
61
64
|
time_tag time, timeago_tag_content(time, time_options), html_options
|
62
65
|
end
|
63
66
|
|
64
67
|
def timeago_tag_content(time, time_options = {}) # :nodoc:
|
65
68
|
time = time.to_date if time_options[:date_only]
|
66
|
-
return time_ago_in_words(time) if time_options[:nojs]
|
69
|
+
return time_ago_in_words(time) if time_options[:nojs] && (time_options[:limit].nil? || time_options[:limit] < time)
|
67
70
|
|
68
|
-
I18n.l time, :
|
71
|
+
I18n.l time, format: time_options[:format]
|
69
72
|
end
|
70
73
|
|
71
74
|
# Return a JavaScript tag to set jQuery timeago locale.
|