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.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +53 -0
  3. data/.travis.yml +7 -9
  4. data/CHANGELOG.md +26 -0
  5. data/Gemfile +9 -2
  6. data/README.md +12 -14
  7. data/Rakefile +14 -12
  8. data/lib/assets/javascripts/rails-timeago-all.js +8 -0
  9. data/lib/assets/javascripts/rails-timeago.js +4 -2
  10. data/lib/rails-timeago.rb +21 -17
  11. data/lib/rails-timeago/helper.rb +13 -10
  12. data/lib/rails-timeago/version.rb +3 -1
  13. data/rails-timeago.gemspec +13 -12
  14. data/spec/rails-timeago_spec.rb +46 -0
  15. data/spec/spec_helper.rb +17 -0
  16. data/spec/support/assets/javascripts/jquery.js +4 -0
  17. data/spec/support/stub.rb +75 -4
  18. data/spec/timeago/helper_spec.rb +157 -110
  19. data/vendor/assets/javascripts/jquery.timeago.js +14 -7
  20. data/vendor/assets/javascripts/locales/jquery.timeago.af.js +30 -20
  21. data/vendor/assets/javascripts/locales/jquery.timeago.am.js +30 -0
  22. data/vendor/assets/javascripts/locales/jquery.timeago.ar.js +13 -5
  23. data/vendor/assets/javascripts/locales/jquery.timeago.az-short.js +30 -0
  24. data/vendor/assets/javascripts/locales/jquery.timeago.az.js +30 -0
  25. data/vendor/assets/javascripts/locales/jquery.timeago.be.js +43 -0
  26. data/vendor/assets/javascripts/locales/jquery.timeago.bg.js +28 -18
  27. data/vendor/assets/javascripts/locales/jquery.timeago.bs.js +13 -7
  28. data/vendor/assets/javascripts/locales/jquery.timeago.ca.js +30 -18
  29. data/vendor/assets/javascripts/locales/jquery.timeago.cs.js +34 -24
  30. data/vendor/assets/javascripts/locales/jquery.timeago.cy.js +30 -20
  31. data/vendor/assets/javascripts/locales/jquery.timeago.da.js +28 -18
  32. data/vendor/assets/javascripts/locales/jquery.timeago.de-short.js +30 -20
  33. data/vendor/assets/javascripts/locales/jquery.timeago.de.js +29 -18
  34. data/vendor/assets/javascripts/locales/jquery.timeago.dv.js +32 -22
  35. data/vendor/assets/javascripts/locales/jquery.timeago.el.js +28 -18
  36. data/vendor/assets/javascripts/locales/jquery.timeago.en-short.js +30 -20
  37. data/vendor/assets/javascripts/locales/jquery.timeago.eo.js +30 -0
  38. data/vendor/assets/javascripts/locales/jquery.timeago.es-short.js +31 -20
  39. data/vendor/assets/javascripts/locales/jquery.timeago.es.js +29 -18
  40. data/vendor/assets/javascripts/locales/jquery.timeago.et.js +28 -18
  41. data/vendor/assets/javascripts/locales/jquery.timeago.eu.js +28 -17
  42. data/vendor/assets/javascripts/locales/jquery.timeago.fa-short.js +30 -20
  43. data/vendor/assets/javascripts/locales/jquery.timeago.fa.js +32 -22
  44. data/vendor/assets/javascripts/locales/jquery.timeago.fi.js +38 -28
  45. data/vendor/assets/javascripts/locales/jquery.timeago.fr-short.js +26 -16
  46. data/vendor/assets/javascripts/locales/jquery.timeago.fr.js +27 -17
  47. data/vendor/assets/javascripts/locales/jquery.timeago.gl.js +28 -18
  48. data/vendor/assets/javascripts/locales/jquery.timeago.he.js +26 -16
  49. data/vendor/assets/javascripts/locales/jquery.timeago.hr.js +53 -48
  50. data/vendor/assets/javascripts/locales/jquery.timeago.hu.js +28 -18
  51. data/vendor/assets/javascripts/locales/jquery.timeago.hy.js +28 -18
  52. data/vendor/assets/javascripts/locales/jquery.timeago.id.js +29 -18
  53. data/vendor/assets/javascripts/locales/jquery.timeago.is.js +29 -19
  54. data/vendor/assets/javascripts/locales/jquery.timeago.it-short.js +30 -20
  55. data/vendor/assets/javascripts/locales/jquery.timeago.it.js +28 -16
  56. data/vendor/assets/javascripts/locales/jquery.timeago.ja.js +29 -19
  57. data/vendor/assets/javascripts/locales/jquery.timeago.jv.js +28 -18
  58. data/vendor/assets/javascripts/locales/jquery.timeago.ka.js +30 -0
  59. data/vendor/assets/javascripts/locales/jquery.timeago.ko.js +31 -20
  60. data/vendor/assets/javascripts/locales/jquery.timeago.ky.js +12 -4
  61. data/vendor/assets/javascripts/locales/jquery.timeago.lt.js +30 -20
  62. data/vendor/assets/javascripts/locales/jquery.timeago.lv.js +30 -20
  63. data/vendor/assets/javascripts/locales/jquery.timeago.mk.js +30 -20
  64. data/vendor/assets/javascripts/locales/jquery.timeago.nl.js +30 -20
  65. data/vendor/assets/javascripts/locales/jquery.timeago.no.js +28 -18
  66. data/vendor/assets/javascripts/locales/jquery.timeago.pl.js +11 -3
  67. data/vendor/assets/javascripts/locales/jquery.timeago.pt-br-short.js +30 -20
  68. data/vendor/assets/javascripts/locales/jquery.timeago.pt-br.js +28 -18
  69. data/vendor/assets/javascripts/locales/jquery.timeago.pt-short.js +30 -20
  70. data/vendor/assets/javascripts/locales/jquery.timeago.pt.js +26 -16
  71. data/vendor/assets/javascripts/locales/jquery.timeago.ro.js +29 -18
  72. data/vendor/assets/javascripts/locales/jquery.timeago.rs.js +53 -48
  73. data/vendor/assets/javascripts/locales/jquery.timeago.ru.js +14 -5
  74. data/vendor/assets/javascripts/locales/jquery.timeago.rw.js +30 -20
  75. data/vendor/assets/javascripts/locales/jquery.timeago.si.js +28 -18
  76. data/vendor/assets/javascripts/locales/jquery.timeago.sk.js +34 -18
  77. data/vendor/assets/javascripts/locales/jquery.timeago.sl.js +45 -39
  78. data/vendor/assets/javascripts/locales/jquery.timeago.sq.js +26 -0
  79. data/vendor/assets/javascripts/locales/jquery.timeago.sr.js +53 -48
  80. data/vendor/assets/javascripts/locales/jquery.timeago.sv.js +28 -18
  81. data/vendor/assets/javascripts/locales/jquery.timeago.th.js +30 -20
  82. data/vendor/assets/javascripts/locales/jquery.timeago.tr-short.js +30 -20
  83. data/vendor/assets/javascripts/locales/jquery.timeago.tr.js +26 -16
  84. data/vendor/assets/javascripts/locales/jquery.timeago.uk.js +12 -4
  85. data/vendor/assets/javascripts/locales/jquery.timeago.ur.js +30 -0
  86. data/vendor/assets/javascripts/locales/jquery.timeago.uz.js +29 -19
  87. data/vendor/assets/javascripts/locales/jquery.timeago.vi.js +30 -20
  88. data/vendor/assets/javascripts/locales/jquery.timeago.zh-CN.js +31 -20
  89. data/vendor/assets/javascripts/locales/jquery.timeago.zh-TW.js +30 -20
  90. metadata +14 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d3b70af4baab360c1b875e4befe0cbfbc37150f1
4
- data.tar.gz: e019a05591543be2575f99b63513a32c6c753ddc
2
+ SHA256:
3
+ metadata.gz: 5653983cf12f0fdc7e6a9652e32a0b416c7df3467e10c94e7cffb4a89d7bd46b
4
+ data.tar.gz: 48da15e4a1f7b9d6a9ddbc05574927d560f92eea17b9e578139f9ed17c142f59
5
5
  SHA512:
6
- metadata.gz: b186f571498592c5fbaad53e5a0da60cdabbd14b32859dd850136847eb60db66fc6a9d274d97f2c8e5588a4a6722eea9d280884eec4fd525bfe7b5e85192df54
7
- data.tar.gz: 190adb567aae0f61fe61353f747662478be56ff59335a2bb22bfaaacefdbd0ca7623603645ea869387211889b80c8fe34f92d7c1cec49bc799aa09f47effc57b
6
+ metadata.gz: 9240a67ff85cf0d11264efcfed29846f988a164a45fca5a576e52d94eba0a6d67fe1ce6c63b0bd1d9ea42d856818573036ccfb6fdca0e0bb5c8ed63aaf35e1d5
7
+ data.tar.gz: 7103a15660b81043bdd7a1e1b0aeda93c94ae5c43098b3376794dd86dea26ec96aaf9201091b15d662baa394eee792e4a0ad29f37c7134acdf9f882809d8dfb7
@@ -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
@@ -1,11 +1,9 @@
1
+ ---
2
+ dist: xenial
1
3
  language: ruby
2
4
  rvm:
3
- - '2.3.0'
4
- - '2.2'
5
- - '2.1'
6
- - '2.0'
7
- - '1.9.3'
8
- - 'rbx-2'
9
- - 'jruby'
10
- before_install:
11
- - gem install bundler
5
+ - 2.7.1
6
+ - 2.6.6
7
+ - 2.5.8
8
+ - 2.4.10
9
+ - 2.3.8
@@ -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 "rake"
9
+ gem 'rake'
10
+ gem 'rake-release'
8
11
  end
9
12
 
10
- gem 'rubysl', platform: :rbx
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://badge.fury.io/rb/rails-timeago.svg)](http://badge.fury.io/rb/rails-timeago)
4
- [![Build Status](https://travis-ci.org/jgraichen/rails-timeago.svg?branch=master)](https://travis-ci.org/jgraichen/rails-timeago)
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, :nojs => true, :limit => 10.days.ago %>
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, :format => options[:format] }`)
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 :limit => proc { 20.days.ago }, :nojs => true
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, :lang => :de %>
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
- require "bundler/gem_tasks"
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 :default => :spec
9
+ task default: :spec
8
10
 
9
11
  desc 'Update jquery-timeago from upstream'
10
12
  task :update do
11
- puts "Clone repository.."
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 "Patch jquery timeago..."
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?("darwin")
23
+ is_mac = RUBY_PLATFORM.downcase.include?('darwin')
22
24
 
23
- Dir["./tmp/locales/*.js"].each do |file|
25
+ Dir['./tmp/locales/*.js'].each do |file|
24
26
  if file =~ /jquery\.timeago\.(.+)\.js$/
25
- `sed -i#{(is_mac)? " ''": nil} "s/timeago.settings.strings/timeago.settings.strings[\\"#{$1}\\"]/" #{file}`
26
- print "#{$1} "
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 "Copying asset files..."
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 "Generate rails-timeago-all.js..."
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["./vendor/assets/javascripts/locales/*.js"].sort.each do |file|
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 "Clean up..."
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
- $(document).on('ready turbolinks:load page:load ajax:success', function() {
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);
@@ -1,11 +1,13 @@
1
- require "rails-timeago/version"
2
- require "rails-timeago/helper"
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', :group => :all do |app|
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 given
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 be converted.
38
- # Global limit should be given as a block to reevaluate limit each time timeago_tag is called.
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 ||= self.option_hash
53
+ @defaults ||= option_hash
51
54
  if opts
52
- @defaults.merge! opts.extract!(*@defaults.keys.select{|k| opts.include?(k)})
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 = self.option_hash
64
+ @defaults = option_hash
61
65
  end
62
66
 
63
67
  def self.option_hash
64
68
  {
65
- :nojs => false,
66
- :force => false,
67
- :format => :default,
68
- :limit => proc { 4.days.ago },
69
- :date_only => true,
70
- :default => '-',
71
- :title => proc { |time, options| I18n.l time, :format => options[:format] }
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
@@ -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" title="Sat, 10 Mar 2012 12:07:07 +0100" data-time-ago="2012-03-10T12:07:07+01:00">2012-03-10</time>"
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 will not be converted.
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.merge! :title => time_options[:title].is_a?(Proc) ? time_options[:title].call(time, time_options) : time_options[:title]
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] or time_range.nil? or time_range.cover?(time)
59
- html_options.merge!('data-time-ago' => time.iso8601)
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] and (time_options[:limit].nil? or time_options[:limit] < time)
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, :format => time_options[:format]
71
+ I18n.l time, format: time_options[:format]
69
72
  end
70
73
 
71
74
  # Return a JavaScript tag to set jQuery timeago locale.