dotiw 5.0.0 → 5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 268158a7bbfdd70af4db14b42aa6f0bf24869a4eda6cefd0eb528598e1f0dfbd
4
- data.tar.gz: 9ee5ba47781f5aa16796641251a02e68997dae148f1b3f4b36f7f7a98a3d7ba6
3
+ metadata.gz: 6c3178c4c07b2647581895e344418e9ce40e3da5d9e3cc1fda714f9817b852e8
4
+ data.tar.gz: cef2e7944c792c501181789e3ed9f0155e12be6954e40664f495bcb298f40709
5
5
  SHA512:
6
- metadata.gz: 4c376145f1d7e62acb4ed59e2ff6ed0a2fd427507a72c69785fd4d01b6efa6a5269f3d1979ce7b3087608d537bc3857c6298b93beafdbca10c701d870578cb0f
7
- data.tar.gz: ab46caf7a03f8ccd459948d3102a363eb0a3978b1e9a76c1344682a89f9b3bd5691090024860a58668ccb89e4566c13b996ae56cc9f64fd8e673b8bdce1da9d3
6
+ metadata.gz: 2db64efc0d3189bca7be013a3faff83820392bcfc69bf111497ea3543d67eba53f3792f62e6c43b1d39b73a6d6fb32811b6ae4f511f04c19d069283cdd18f355
7
+ data.tar.gz: a9bae3a175fada3623c8275abec2052e377716db914dadd0b2908a33fbff67fa95191062cb37cb20d15a90478b61ddc9647140d04dc37f0be73fd44b833e7957
@@ -1,3 +1,8 @@
1
+ ## 5.1.0 (2020/08/05)
2
+
3
+ * [#111](https://github.com/radar/distance_of_time_in_words/pull/111): Fix: `NoMethodError` when calling `ActionController::Base.helpers.distance_of_time_in_words` - [@denisahearn](https://github.com/denisahearn).
4
+ * [#106](https://github.com/radar/distance_of_time_in_words/pull/106): Add Vietnamese language support - [@runlevel5 ](https://github.com/runlevel5).
5
+
1
6
  ## 5.0.0 (2020/05/07)
2
7
 
3
8
  * [#105](https://github.com/radar/distance_of_time_in_words/pull/105): Support for Ruby w/o Rails - [@dblock](https://github.com/dblock).
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = DOTIW::VERSION
9
9
  s.licenses = ['MIT']
10
10
 
11
- s.authors = ["Ryan Bigg", "Lauran Jansen"]
11
+ s.authors = ['Ryan Bigg', 'Lauran Jansen']
12
12
  s.description = "dotiw is a gem for Rails that overrides the
13
13
  default distance_of_time_in_words and provides
14
14
  a more accurate output. Do you crave accuracy
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.email = ['radarlistener@gmail.com', 'github@lauranjansen.com']
19
19
  s.homepage = 'https://github.com/radar/distance_of_time_in_words'
20
20
 
21
- s.add_dependency 'i18n'
22
21
  s.add_dependency 'activesupport'
22
+ s.add_dependency 'i18n'
23
23
 
24
24
  s.add_development_dependency 'appraisal'
25
25
  s.add_development_dependency 'bundler'
@@ -23,11 +23,18 @@ module DOTIW
23
23
  I18n.reload!
24
24
  end
25
25
 
26
- protected
26
+ def languages
27
+ @languages ||= (locale_files.map { |path| path.split(%r{[/.]})[-2].to_sym })
28
+ end
27
29
 
28
- # Returns all locale files shipped with library
29
30
  def locale_files
30
- Dir[File.join(File.dirname(__FILE__), 'dotiw', 'locale', '**/*')]
31
+ files 'dotiw/locale', '*.yml'
32
+ end
33
+
34
+ protected
35
+
36
+ def files(directory, ext)
37
+ Dir[File.join File.dirname(__FILE__), directory, ext]
31
38
  end
32
39
  end # DOTIW
33
40
 
@@ -10,7 +10,7 @@ module ActionView
10
10
 
11
11
  def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
12
12
  return _distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague)
13
- super
13
+ DOTIW::Methods.distance_of_time_in_words(from_time, to_time, include_seconds_or_options, options)
14
14
  end
15
15
 
16
16
  def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
@@ -0,0 +1,25 @@
1
+ vi:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 giây
6
+ other: "%{count} giây"
7
+ minutes:
8
+ one: 1 phút
9
+ other: "%{count} phút"
10
+ hours:
11
+ one: 1 giờ
12
+ other: "%{count} giờ"
13
+ days:
14
+ one: 1 ngày
15
+ other: "%{count} ngày"
16
+ weeks:
17
+ one: 1 tuần
18
+ other: "%{count} tuần"
19
+ months:
20
+ one: 1 tháng
21
+ other: "%{count} tháng"
22
+ years:
23
+ one: 1 năm
24
+ other: "%{count} năm"
25
+ less_than_x: "ít hơn %{distance}"
@@ -2,6 +2,8 @@
2
2
 
3
3
  module DOTIW
4
4
  module Methods
5
+ extend self
6
+
5
7
  def distance_of_time_in_words_hash(from_time, to_time, options = {})
6
8
  from_time = from_time.to_time if !from_time.is_a?(Time) && from_time.respond_to?(:to_time)
7
9
  to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DOTIW
4
- VERSION = '5.0.0'
4
+ VERSION = '5.1.0'
5
5
  end
@@ -7,6 +7,8 @@ describe 'A better distance_of_time_in_words' do
7
7
  include ActionView::Helpers::DateHelper
8
8
  include ActionView::Helpers::TextHelper
9
9
  include ActionView::Helpers::NumberHelper
10
+
11
+ require 'action_controller'
10
12
  else
11
13
  include DOTIW::Methods
12
14
  end
@@ -19,7 +21,7 @@ describe 'A better distance_of_time_in_words' do
19
21
  allow(Time.zone).to receive(:now).and_return(START_TIME)
20
22
  end
21
23
 
22
- describe 'distance of time' do
24
+ describe '#distance_of_time' do
23
25
  [
24
26
  [0.5.minutes, '30 seconds'],
25
27
  [4.5.minutes, '4 minutes and 30 seconds'],
@@ -48,7 +50,7 @@ describe 'A better distance_of_time_in_words' do
48
50
  end
49
51
  end
50
52
 
51
- describe 'hash version' do
53
+ describe '#distance_of_time_in_words_hash' do
52
54
  describe 'giving correct numbers of' do
53
55
  %i[years months weeks days minutes seconds].each do |name|
54
56
  describe name do
@@ -80,15 +82,50 @@ describe 'A better distance_of_time_in_words' do
80
82
  end
81
83
  end
82
84
 
83
- describe 'real version' do
84
- it 'debe hablar español' do
85
- expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, locale: :es)).to eq('un día')
86
- expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, locale: :es)).to eq('5 días')
85
+ describe '#time_ago_in_words' do
86
+ it 'aliases to distance_of_time_in_words' do
87
+ expect(time_ago_in_words(Time.now - 3.days - 14.minutes)).to eq('3 days and 14 minutes')
87
88
  end
89
+ end
90
+
91
+ describe '#distance_of_time_in_words' do
92
+ context 'locale' do
93
+ it 'includes known languages' do
94
+ expect(DOTIW.languages).to include :en
95
+ expect(DOTIW.languages).to include :ru
96
+ end
88
97
 
89
- it "deve parlare l'italiano" do
90
- expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, true, locale: :it)).to eq('un giorno')
91
- expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, true, locale: :it)).to eq('5 giorni')
98
+ it 'includes all the languages in specs' do
99
+ languages = Dir[File.join(File.dirname(__FILE__), 'i18n', '*.yml')].map { |f| File.basename(f, '.yml') }
100
+ expect(DOTIW.languages.map(&:to_s).sort).to eq languages.sort
101
+ end
102
+
103
+ DOTIW.languages.each do |lang|
104
+ context lang do
105
+ YAML.safe_load(
106
+ File.read(
107
+ File.join(
108
+ File.dirname(__FILE__), 'i18n', "#{lang}.yml"
109
+ )
110
+ )
111
+ ).each_pair do |category, fixtures|
112
+ context category do
113
+ fixtures.each_pair do |k, v|
114
+ it v do
115
+ expect(
116
+ distance_of_time_in_words(
117
+ START_TIME,
118
+ START_TIME + eval(k),
119
+ true,
120
+ locale: lang
121
+ )
122
+ ).to eq(v)
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
92
129
  end
93
130
 
94
131
  [
@@ -145,7 +182,7 @@ describe 'A better distance_of_time_in_words' do
145
182
  end
146
183
  end
147
184
 
148
- describe 'accumulate on' do
185
+ describe 'accumulate_on:' do
149
186
  [
150
187
  [START_TIME,
151
188
  START_TIME + 10.minute,
@@ -298,6 +335,21 @@ describe 'A better distance_of_time_in_words' do
298
335
  expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
299
336
  end
300
337
  end
338
+
339
+ context 'via ActionController::Base.helpers' do
340
+ it '#distance_of_time_in_words' do
341
+ end_time = START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds
342
+ expected = '1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds'
343
+ actual = ActionController::Base.helpers.distance_of_time_in_words(START_TIME, end_time, true, { vague: false })
344
+ expect(actual).to eq(expected)
345
+ end
346
+
347
+ it '#time_ago_in_words' do
348
+ expected = '3 days and 14 minutes'
349
+ actual = ActionController::Base.helpers.time_ago_in_words(Time.now - 3.days - 14.minutes)
350
+ expect(actual).to eq(expected)
351
+ end
352
+ end
301
353
  end
302
354
  end
303
355
 
@@ -307,9 +359,13 @@ describe 'A better distance_of_time_in_words' do
307
359
  end
308
360
 
309
361
  it 'removes seconds in all other cases' do
310
- expect(distance_of_time_in_words(START_TIME,
311
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
312
- false)).to eq('1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes')
362
+ expect(
363
+ distance_of_time_in_words(
364
+ START_TIME,
365
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
366
+ false
367
+ )
368
+ ).to eq('1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes')
313
369
  end
314
370
  end # include_seconds
315
371
  end
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: ثانية واحدة
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekund
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 Sekunde
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 second
@@ -0,0 +1,3 @@
1
+ days:
2
+ 1.day: un día
3
+ 5.days: 5 días
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 seconde
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 detik
@@ -0,0 +1,3 @@
1
+ days:
2
+ 1.day: un giorno
3
+ 5.days: 5 giorni
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1秒
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 일 초
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekund
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 seconde
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekunda
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 segundo
@@ -0,0 +1,5 @@
1
+ seconds:
2
+ 0.5.seconds: меньше, чем 1 секунда
3
+ 1.second: 1 секунда
4
+ minutes:
5
+ 1.minute: 1 минута
@@ -0,0 +1,22 @@
1
+ seconds:
2
+ 0.5.second: ít hơn 1 giây
3
+ 1.second: 1 giây
4
+ 3.seconds: 3 giây
5
+ minutes:
6
+ 1.minute: 1 phút
7
+ 10.minutes: 10 phút
8
+ hours:
9
+ 1.hour: 1 giờ
10
+ 2.hours: 2 giờ
11
+ days:
12
+ 1.day: 1 ngày
13
+ 2.days: 2 ngày
14
+ weeks:
15
+ 1.week: 1 tuần
16
+ 2.weeks: 2 tuần
17
+ months:
18
+ 1.month: 1 tháng
19
+ 2.months: 2 tháng
20
+ years:
21
+ 1.year: 1 năm
22
+ 2.years: 2 năm
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 秒
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotiw
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-06 00:00:00.000000000 Z
12
+ date: 2020-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: i18n
15
+ name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: activesupport
29
+ name: i18n
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -170,11 +170,29 @@ files:
170
170
  - lib/dotiw/locale/pl.yml
171
171
  - lib/dotiw/locale/pt-BR.yml
172
172
  - lib/dotiw/locale/ru.yml
173
+ - lib/dotiw/locale/vi.yml
173
174
  - lib/dotiw/locale/zh-CN.yml
174
175
  - lib/dotiw/methods.rb
175
176
  - lib/dotiw/time_hash.rb
176
177
  - lib/dotiw/version.rb
177
178
  - spec/lib/dotiw_spec.rb
179
+ - spec/lib/i18n/ar.yml
180
+ - spec/lib/i18n/da.yml
181
+ - spec/lib/i18n/de.yml
182
+ - spec/lib/i18n/en.yml
183
+ - spec/lib/i18n/es.yml
184
+ - spec/lib/i18n/fr.yml
185
+ - spec/lib/i18n/id.yml
186
+ - spec/lib/i18n/it.yml
187
+ - spec/lib/i18n/ja.yml
188
+ - spec/lib/i18n/ko.yml
189
+ - spec/lib/i18n/nb.yml
190
+ - spec/lib/i18n/nl.yml
191
+ - spec/lib/i18n/pl.yml
192
+ - spec/lib/i18n/pt-BR.yml
193
+ - spec/lib/i18n/ru.yml
194
+ - spec/lib/i18n/vi.yml
195
+ - spec/lib/i18n/zh-CN.yml
178
196
  - spec/spec_helper.rb
179
197
  homepage: https://github.com/radar/distance_of_time_in_words
180
198
  licenses:
@@ -195,10 +213,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
213
  - !ruby/object:Gem::Version
196
214
  version: '0'
197
215
  requirements: []
198
- rubygems_version: 3.1.3
216
+ rubygems_version: 3.1.2
199
217
  signing_key:
200
218
  specification_version: 4
201
219
  summary: Better distance_of_time_in_words for Rails
202
220
  test_files:
203
221
  - spec/lib/dotiw_spec.rb
222
+ - spec/lib/i18n/ar.yml
223
+ - spec/lib/i18n/da.yml
224
+ - spec/lib/i18n/de.yml
225
+ - spec/lib/i18n/en.yml
226
+ - spec/lib/i18n/es.yml
227
+ - spec/lib/i18n/fr.yml
228
+ - spec/lib/i18n/id.yml
229
+ - spec/lib/i18n/it.yml
230
+ - spec/lib/i18n/ja.yml
231
+ - spec/lib/i18n/ko.yml
232
+ - spec/lib/i18n/nb.yml
233
+ - spec/lib/i18n/nl.yml
234
+ - spec/lib/i18n/pl.yml
235
+ - spec/lib/i18n/pt-BR.yml
236
+ - spec/lib/i18n/ru.yml
237
+ - spec/lib/i18n/vi.yml
238
+ - spec/lib/i18n/zh-CN.yml
204
239
  - spec/spec_helper.rb