dotiw 4.0.1 → 5.0.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.
@@ -1,17 +1,10 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  ROOT_PATH = File.join(File.dirname(__FILE__), '..')
4
- $:.unshift ROOT_PATH unless $:.include? ROOT_PATH
5
-
6
- # Files that are usually required by Rails, but in a testing context will not be.
7
- require 'erb'
8
-
9
- require 'active_support/all'
10
- require 'action_view'
4
+ $LOAD_PATH.unshift ROOT_PATH unless $LOAD_PATH.include? ROOT_PATH
11
5
 
12
6
  require 'dotiw'
13
7
 
14
8
  Time.zone = 'UTC'
15
9
 
16
- I18n.load_path << Dir[File.join(File.dirname(__FILE__), 'translations', '*')]
17
10
  I18n.locale = :en
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotiw
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  - Lauran Jansen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-08 00:00:00.000000000 Z
12
+ date: 2020-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: actionpack
15
+ name: i18n
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4'
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '4'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: i18n
29
+ name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rake
43
+ name: appraisal
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -68,21 +68,21 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rspec
71
+ name: pry
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '3.0'
76
+ version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '3.0'
83
+ version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: tzinfo
85
+ name: rake
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,33 +96,33 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: appraisal
99
+ name: rspec
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: '3.0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: '3.0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: pry
113
+ name: tzinfo
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 1.2.7
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 1.2.7
126
126
  description: |-
127
127
  dotiw is a gem for Rails that overrides the
128
128
  default distance_of_time_in_words and provides
@@ -136,8 +136,10 @@ executables: []
136
136
  extensions: []
137
137
  extra_rdoc_files: []
138
138
  files:
139
+ - ".github/workflows/ruby.yml"
139
140
  - ".gitignore"
140
- - ".travis.yml"
141
+ - ".rspec"
142
+ - Appraisals
141
143
  - CHANGELOG.md
142
144
  - CONTRIBUTING.md
143
145
  - Gemfile
@@ -149,8 +151,10 @@ files:
149
151
  - gemfiles/rails_4.gemfile
150
152
  - gemfiles/rails_5.0.gemfile
151
153
  - gemfiles/rails_5.1.gemfile
154
+ - gemfiles/rails_5.2.gemfile
155
+ - gemfiles/rails_6.0.gemfile
152
156
  - lib/dotiw.rb
153
- - lib/dotiw/action_view_ext/helpers/date_helper.rb
157
+ - lib/dotiw/action_view/helpers/date_helper.rb
154
158
  - lib/dotiw/locale/ar.yml
155
159
  - lib/dotiw/locale/da.yml
156
160
  - lib/dotiw/locale/de.yml
@@ -167,15 +171,16 @@ files:
167
171
  - lib/dotiw/locale/pt-BR.yml
168
172
  - lib/dotiw/locale/ru.yml
169
173
  - lib/dotiw/locale/zh-CN.yml
174
+ - lib/dotiw/methods.rb
170
175
  - lib/dotiw/time_hash.rb
171
176
  - lib/dotiw/version.rb
172
177
  - spec/lib/dotiw_spec.rb
173
178
  - spec/spec_helper.rb
174
- homepage: https://github.com/radar/dotiw
179
+ homepage: https://github.com/radar/distance_of_time_in_words
175
180
  licenses:
176
181
  - MIT
177
182
  metadata: {}
178
- post_install_message:
183
+ post_install_message:
179
184
  rdoc_options: []
180
185
  require_paths:
181
186
  - lib
@@ -190,9 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
195
  - !ruby/object:Gem::Version
191
196
  version: '0'
192
197
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.7.3
195
- signing_key:
198
+ rubygems_version: 3.1.3
199
+ signing_key:
196
200
  specification_version: 4
197
201
  summary: Better distance_of_time_in_words for Rails
198
202
  test_files:
@@ -1,27 +0,0 @@
1
- rvm:
2
- - 2.4.0
3
- - 2.3.0
4
- - 2.2.4
5
- - 2.1.8
6
- - 2.0.0
7
- - jruby-19mode
8
- gemfile:
9
- - gemfiles/rails_4.gemfile
10
- - gemfiles/rails_5.0.gemfile
11
- - gemfiles/rails_5.1.gemfile
12
- before_install:
13
- - gem update --system
14
- - gem update bundler
15
- install: "bundle install"
16
-
17
- matrix:
18
- exclude:
19
- # Rails 5 requires Ruby >= 2.2.2
20
- - rvm: 2.0.0
21
- gemfile: gemfiles/rails_5.0.gemfile
22
- - rvm: 2.0.0
23
- gemfile: gemfiles/rails_5.1.gemfile
24
- - rvm: 2.1.8
25
- gemfile: gemfiles/rails_5.0.gemfile
26
- - rvm: 2.1.8
27
- gemfile: gemfiles/rails_5.1.gemfile
@@ -1,103 +0,0 @@
1
- module ActionView
2
- module Helpers
3
- module DateHelper
4
- alias_method :old_distance_of_time_in_words, :distance_of_time_in_words
5
-
6
- def distance_of_time_in_words_hash(from_time, to_time, options = {})
7
- from_time = from_time.to_time if !from_time.is_a?(Time) && from_time.respond_to?(:to_time)
8
- to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time)
9
-
10
- DOTIW::TimeHash.new(nil, from_time, to_time, options).to_hash
11
- end
12
-
13
- def distance_of_time(seconds, options = {})
14
- options[:include_seconds] ||= true
15
- display_time_in_words DOTIW::TimeHash.new(seconds, nil, nil, options).to_hash, options
16
- end
17
-
18
- def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
19
- if include_seconds_or_options.is_a?(Hash)
20
- options = include_seconds_or_options
21
- else
22
- options[:include_seconds] ||= !!include_seconds_or_options
23
- end
24
- return distance_of_time(from_time, options) if to_time == 0
25
- return old_distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague)
26
- hash = distance_of_time_in_words_hash(from_time, to_time, options)
27
- display_time_in_words(hash, options)
28
- end
29
-
30
- def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
31
- options[:precision] ||= 0
32
- distance = to_time - from_time
33
- result = ((current_time - from_time) / distance) * 100
34
- number_with_precision(result, options).to_s + "%"
35
- end
36
-
37
- alias_method :old_time_ago_in_words, :time_ago_in_words
38
-
39
- def time_ago_in_words(from_time, include_seconds_or_options = {})
40
- distance_of_time_in_words(from_time, Time.current, include_seconds_or_options)
41
- end
42
-
43
- private
44
- def display_time_in_words(hash, options = {})
45
- options.reverse_merge!(
46
- :include_seconds => false
47
- ).symbolize_keys!
48
-
49
- include_seconds = options.delete(:include_seconds)
50
- hash.delete(:seconds) if !include_seconds && hash[:minutes]
51
-
52
- options[:except] = Array.wrap(options[:except]).map!(&:to_sym) if options[:except]
53
- options[:only] = Array.wrap(options[:only]).map!(&:to_sym) if options[:only]
54
-
55
- # Remove all the values that are nil or excluded. Keep the required ones.
56
- hash.delete_if do |key, value|
57
- value.nil? || value.zero? ||
58
- (options[:except] && options[:except].include?(key)) ||
59
- (options[:only] && !options[:only].include?(key))
60
- end
61
-
62
- i18n_scope = options.delete(:scope) || DOTIW::DEFAULT_I18N_SCOPE
63
- if hash.empty?
64
- fractions = DOTIW::TimeHash::TIME_FRACTIONS
65
- fractions = fractions & options[:only] if options[:only]
66
- fractions = fractions - options[:except] if options[:except]
67
-
68
- I18n.with_options :locale => options[:locale], :scope => i18n_scope do |locale|
69
- # e.g. try to format 'less than 1 days', fallback to '0 days'
70
- return locale.translate :less_than_x,
71
- :distance => locale.translate(fractions.first, :count => 1),
72
- :default => locale.translate(fractions.first, :count => 0)
73
- end
74
- end
75
-
76
- output = []
77
- I18n.with_options :locale => options[:locale], :scope => i18n_scope do |locale|
78
- output = hash.map { |key, value| locale.t(key, :count => value) }
79
- end
80
-
81
- options.delete(:except)
82
- options.delete(:only)
83
- highest_measures = options.delete(:highest_measures)
84
- highest_measures = 1 if options.delete(:highest_measure_only)
85
- if highest_measures
86
- output = output[0...highest_measures]
87
- end
88
-
89
- options[:words_connector] ||= I18n.translate :'datetime.dotiw.words_connector',
90
- :default => :'support.array.words_connector',
91
- :locale => options[:locale]
92
- options[:two_words_connector] ||= I18n.translate :'datetime.dotiw.two_words_connector',
93
- :default => :'support.array.two_words_connector',
94
- :locale => options[:locale]
95
- options[:last_word_connector] ||= I18n.translate :'datetime.dotiw.last_word_connector',
96
- :default => :'support.array.last_word_connector',
97
- :locale => options[:locale]
98
-
99
- output.to_sentence(options)
100
- end
101
- end # DateHelper
102
- end # Helpers
103
- end # ActionView