dotiw 3.0.1 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +45 -0
  3. data/.gitignore +2 -1
  4. data/.rspec +2 -0
  5. data/Appraisals +19 -0
  6. data/CHANGELOG.md +29 -0
  7. data/CONTRIBUTING.md +34 -0
  8. data/Gemfile +2 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.markdown +139 -70
  11. data/Rakefile +3 -1
  12. data/dotiw.gemspec +22 -17
  13. data/gemfiles/.bundle/config +2 -0
  14. data/gemfiles/rails_4.gemfile +9 -0
  15. data/gemfiles/rails_5.0.gemfile +9 -0
  16. data/gemfiles/rails_5.1.gemfile +9 -0
  17. data/gemfiles/rails_5.2.gemfile +9 -0
  18. data/gemfiles/rails_6.0.gemfile +9 -0
  19. data/lib/dotiw.rb +31 -13
  20. data/lib/dotiw/action_view/helpers/date_helper.rb +24 -0
  21. data/lib/dotiw/locale/ar.yml +53 -0
  22. data/lib/dotiw/locale/da.yml +23 -0
  23. data/lib/dotiw/locale/fr.yml +25 -0
  24. data/lib/dotiw/locale/id.yml +25 -0
  25. data/lib/dotiw/locale/ko.yml +25 -0
  26. data/lib/dotiw/locale/pl.yml +7 -0
  27. data/lib/dotiw/locale/pt-BR.yml +25 -0
  28. data/lib/dotiw/locale/vi.yml +25 -0
  29. data/lib/dotiw/locale/zh-CN.yml +25 -0
  30. data/lib/dotiw/methods.rb +93 -0
  31. data/lib/dotiw/time_hash.rb +65 -38
  32. data/lib/dotiw/version.rb +2 -2
  33. data/spec/lib/dotiw_spec.rb +264 -159
  34. data/spec/lib/i18n/ar.yml +2 -0
  35. data/spec/lib/i18n/da.yml +2 -0
  36. data/spec/lib/i18n/de.yml +2 -0
  37. data/spec/lib/i18n/en.yml +2 -0
  38. data/spec/lib/i18n/es.yml +3 -0
  39. data/spec/lib/i18n/fr.yml +2 -0
  40. data/spec/lib/i18n/id.yml +2 -0
  41. data/spec/lib/i18n/it.yml +3 -0
  42. data/spec/lib/i18n/ja.yml +2 -0
  43. data/spec/lib/i18n/ko.yml +2 -0
  44. data/spec/lib/i18n/nb.yml +2 -0
  45. data/spec/lib/i18n/nl.yml +2 -0
  46. data/spec/lib/i18n/pl.yml +2 -0
  47. data/spec/lib/i18n/pt-BR.yml +2 -0
  48. data/spec/lib/i18n/ru.yml +5 -0
  49. data/spec/lib/i18n/vi.yml +22 -0
  50. data/spec/lib/i18n/zh-CN.yml +2 -0
  51. data/spec/spec_helper.rb +2 -9
  52. metadata +110 -21
  53. data/.travis.yml +0 -5
  54. data/lib/dotiw/action_view_ext/helpers/date_helper.rb +0 -103
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'rake'
3
5
  require 'bundler'
@@ -9,4 +11,4 @@ Bundler::GemHelper.install_tasks
9
11
 
10
12
  RSpec::Core::RakeTask.new(:spec)
11
13
 
12
- task :default => :spec
14
+ task default: :spec
@@ -1,30 +1,35 @@
1
- # dotiw.gemspec
2
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
3
2
 
4
- $:.push File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
5
4
  require 'dotiw/version'
6
5
 
7
6
  Gem::Specification.new do |s|
8
7
  s.name = 'dotiw'
9
8
  s.version = DOTIW::VERSION
9
+ s.licenses = ['MIT']
10
10
 
11
- s.authors = ["Ryan Bigg"]
12
- s.date = %q{2015-04-09}
13
- s.description = "Better distance_of_time_in_words for Rails"
14
- s.summary = "Better distance_of_time_in_words for Rails"
15
- s.email = "radarlistener@gmail.com"
11
+ s.authors = ['Ryan Bigg', 'Lauran Jansen']
12
+ s.description = "dotiw is a gem for Rails that overrides the
13
+ default distance_of_time_in_words and provides
14
+ a more accurate output. Do you crave accuracy
15
+ down to the second? So do I. That's why I made
16
+ this gem. - Ryan"
17
+ s.summary = 'Better distance_of_time_in_words for Rails'
18
+ s.email = ['radarlistener@gmail.com', 'github@lauranjansen.com']
19
+ s.homepage = 'https://github.com/radar/distance_of_time_in_words'
16
20
 
17
- s.add_dependency "actionpack", ">= 3"
18
- s.add_dependency "i18n"
21
+ s.add_dependency 'activesupport'
22
+ s.add_dependency 'i18n'
19
23
 
20
- s.add_development_dependency "rake"
21
- s.add_development_dependency "bundler"
22
- s.add_development_dependency "rspec", "~> 3.0"
23
- s.add_development_dependency "tzinfo"
24
+ s.add_development_dependency 'appraisal'
25
+ s.add_development_dependency 'bundler'
26
+ s.add_development_dependency 'pry'
27
+ s.add_development_dependency 'rake'
28
+ s.add_development_dependency 'rspec', '~> 3.0'
29
+ s.add_development_dependency 'tzinfo', '~> 1.2.7'
24
30
 
25
31
  s.files = `git ls-files`.split("\n")
26
32
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
- s.require_paths = ["lib"]
33
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
34
+ s.require_paths = ['lib']
29
35
  end
30
-
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'http://rubygems.org'
6
+
7
+ gem 'rails', '~> 4.0'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'http://rubygems.org'
6
+
7
+ gem 'rails', '~> 5.0.0'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'http://rubygems.org'
6
+
7
+ gem 'rails', '~> 5.1.0'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'http://rubygems.org'
6
+
7
+ gem 'rails', '~> 5.2.0'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'http://rubygems.org'
6
+
7
+ gem 'rails', '~> 6.0.0'
8
+
9
+ gemspec path: '../'
@@ -1,30 +1,48 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'i18n'
4
4
 
5
- # Rails hacks
6
- if defined?(ActionView::Helpers)
7
- require 'dotiw/action_view_ext/helpers/date_helper'
8
- end
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
9
7
 
10
8
  module DOTIW
9
+ extend ActiveSupport::Autoload
10
+
11
+ eager_autoload do
12
+ autoload :VERSION, 'dotiw/version'
13
+ autoload :TimeHash, 'dotiw/time_hash'
14
+ autoload :Methods, 'dotiw/methods'
15
+ end
16
+
11
17
  extend self
12
-
13
- autoload :VERSION, 'dotiw/version'
14
- autoload :TimeHash, 'dotiw/time_hash'
15
18
 
16
19
  DEFAULT_I18N_SCOPE = :'datetime.dotiw'
17
20
 
18
- def init_i18n
21
+ def init_i18n!
19
22
  I18n.load_path.unshift(*locale_files)
20
23
  I18n.reload!
21
24
  end
22
25
 
23
- protected
24
- # Returns all locale files shipped with library
26
+ def languages
27
+ @languages ||= (locale_files.map { |path| path.split(%r{[/.]})[-2].to_sym })
28
+ end
29
+
25
30
  def locale_files
26
- 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]
27
38
  end
28
39
  end # DOTIW
29
40
 
30
- DOTIW.init_i18n
41
+ DOTIW.init_i18n!
42
+
43
+ begin
44
+ require 'action_view'
45
+ require_relative 'dotiw/action_view/helpers/date_helper'
46
+ rescue LoadError
47
+ # TODO: don't rely on exception
48
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module DateHelper
6
+ alias_method :_distance_of_time_in_words, :distance_of_time_in_words
7
+ alias_method :_time_ago_in_words, :time_ago_in_words
8
+
9
+ include DOTIW::Methods
10
+
11
+ def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
12
+ return _distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague)
13
+ DOTIW::Methods.distance_of_time_in_words(from_time, to_time, include_seconds_or_options, options)
14
+ end
15
+
16
+ def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
17
+ options[:precision] ||= 0
18
+ distance = to_time - from_time
19
+ result = ((current_time - from_time) / distance) * 100
20
+ number_with_precision(result, options).to_s + '%'
21
+ end
22
+ end # DateHelper
23
+ end # Helpers
24
+ end # ActionView
@@ -0,0 +1,53 @@
1
+ ar:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ zero: ثانية
6
+ one: ثانية واحدة
7
+ two: ثانيتين
8
+ few: "%{count} توانٍ"
9
+ many: "%{count} ثانية"
10
+ other: "%{count} ثانية"
11
+ minutes:
12
+ zero: دقيقة
13
+ one: دقيقة واحدة
14
+ two: دقيقتين
15
+ few: "%{count} دقائق"
16
+ many: "%{count} دقيقة"
17
+ other: "%{count} دقيقة"
18
+ hours:
19
+ zero: ساعة
20
+ one: ساعة واحدة
21
+ two: ساعتين
22
+ few: "%{count} ساعات"
23
+ many: "%{count} ساعة"
24
+ other: "%{count} ساعة"
25
+ days:
26
+ zero: يوم
27
+ one: يوم واحد
28
+ two: يومين
29
+ few: "%{count} أيام"
30
+ many: "%{count} يومًا"
31
+ other: "%{count} يوم"
32
+ weeks:
33
+ zero: أسبوع
34
+ one: أسبوع واحدة
35
+ two: أسبوعين
36
+ few: "%{count} أسابيع"
37
+ many: "%{count} أسابيع"
38
+ other: "%{count} أسيوع"
39
+ months:
40
+ zero: شهر
41
+ one: شهر واحد
42
+ two: شهرين
43
+ few: "%{count} أشهر"
44
+ many: "%{count} شهراً"
45
+ other: "%{count} شهر"
46
+ years:
47
+ zero: عام
48
+ one: عام واحد
49
+ two: عامين
50
+ few: "%{count} أعوام"
51
+ many: "%{count} عاماً"
52
+ other: "%{count} عام"
53
+ less_than_x: "%{distance} أقل من"
@@ -0,0 +1,23 @@
1
+ da:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: "1 sekund"
6
+ other: "%{count} sekunder"
7
+ minutes:
8
+ one: "1 minut"
9
+ other: "%{count} minutter"
10
+ hours:
11
+ one: "1 time"
12
+ other: "%{count} timer"
13
+ days:
14
+ one: "1 dag"
15
+ other: "%{count} dage"
16
+ weeks:
17
+ one: "1 uge"
18
+ other: "%{count} uger"
19
+ months:
20
+ one: "1 måned"
21
+ other: "%{count} måneder"
22
+ years: "%{count} år"
23
+ less_than_x: "mindre end %{distance}"
@@ -0,0 +1,25 @@
1
+ fr:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 seconde
6
+ other: "%{count} secondes"
7
+ minutes:
8
+ one: 1 minute
9
+ other: "%{count} minutes"
10
+ hours:
11
+ one: 1 heure
12
+ other: "%{count} heures"
13
+ days:
14
+ one: 1 jour
15
+ other: "%{count} jours"
16
+ weeks:
17
+ one: 1 semaine
18
+ other: "%{count} semaines"
19
+ months:
20
+ one: 1 mois
21
+ other: "%{count} mois"
22
+ years:
23
+ one: 1 an
24
+ other: "%{count} ans"
25
+ less_than_x: "moins de %{distance}"
@@ -0,0 +1,25 @@
1
+ id:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 detik
6
+ other: "%{count} detik"
7
+ minutes:
8
+ one: 1 menit
9
+ other: "%{count} menit"
10
+ hours:
11
+ one: 1 jam
12
+ other: "%{count} jam"
13
+ days:
14
+ one: 1 hari
15
+ other: "%{count} hari"
16
+ weeks:
17
+ one: 1 minggu
18
+ other: "%{count} minggu"
19
+ months:
20
+ one: 1 bulan
21
+ other: "%{count} bulan"
22
+ years:
23
+ one: 1 tahun
24
+ other: "%{count} tahun"
25
+ less_than_x: "kurang dari %{distance}"
@@ -0,0 +1,25 @@
1
+ ko:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 일 초
6
+ other: "%{count} 초"
7
+ minutes:
8
+ one: 일 분
9
+ other: "%{count} 분"
10
+ hours:
11
+ one: 한 시간
12
+ other: "%{count} 시간"
13
+ days:
14
+ one: 하루
15
+ other: "%{count} 일"
16
+ weeks:
17
+ one: 일주
18
+ other: "%{count} 주"
19
+ months:
20
+ one: 한 달
21
+ other: "%{count} 달"
22
+ years:
23
+ one: 일년
24
+ other: "%{count} 년"
25
+ less_than_x: "%{distance} 미만"
@@ -4,29 +4,36 @@ pl:
4
4
  seconds:
5
5
  one: "1 sekunda"
6
6
  few: "%{count} sekundy"
7
+ many: "%{count} sekund"
7
8
  other: "%{count} sekund"
8
9
  minutes:
9
10
  one: "1 minuta"
10
11
  few: "%{count} minuty"
12
+ many: "%{count} minut"
11
13
  other: "%{count} minut"
12
14
  hours:
13
15
  one: "1 godzina"
14
16
  few: "%{count} godziny"
17
+ many: "%{count} godzin"
15
18
  other: "%{count} godzin"
16
19
  days:
17
20
  one: "1 dzień"
18
21
  few: "%{count} dni"
22
+ many: "%{count} dni"
19
23
  other: "%{count} dni"
20
24
  weeks:
21
25
  one: "1 tydzień"
22
26
  few: "%{count} tygodnie"
27
+ many: "%{count} tygodni"
23
28
  other: "%{count} tygodni"
24
29
  months:
25
30
  one: "1 miesiąc"
26
31
  few: "%{count} miesiące"
32
+ many: "%{count} miesięcy"
27
33
  other: "%{count} miesięcy"
28
34
  years:
29
35
  one: "1 rok"
30
36
  few: "%{count} lata"
37
+ many: "%{count} lat"
31
38
  other: "%{count} lat"
32
39
  less_than_x: "mniej niż %{distance}"
@@ -0,0 +1,25 @@
1
+ pt-BR:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 segundo
6
+ other: "%{count} segundos"
7
+ minutes:
8
+ one: 1 minuto
9
+ other: "%{count} minutos"
10
+ hours:
11
+ one: 1 hora
12
+ other: "%{count} horas"
13
+ days:
14
+ one: 1 dia
15
+ other: "%{count} dias"
16
+ weeks:
17
+ one: 1 semana
18
+ other: "%{count} semanas"
19
+ months:
20
+ one: 1 mês
21
+ other: "%{count} meses"
22
+ years:
23
+ one: 1 ano
24
+ other: "%{count} anos"
25
+ less_than_x: "menos de %{distance}"
@@ -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}"