i18n-tasks 0.8.3 → 0.8.4

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
  SHA1:
3
- metadata.gz: 0198838a2cf17a2fc7a9913b57834523ace51815
4
- data.tar.gz: 7be76e4bc18d61ad4083dae29effdd766fe3c2d1
3
+ metadata.gz: 6927148f79d82a7dfc85f9ed1551c65ab5534e34
4
+ data.tar.gz: 16af9b34933d2e3101c55e8c0edd0da014faa286
5
5
  SHA512:
6
- metadata.gz: bc3e3b650239a541435b7ee77b375e04e4d18c2a64ee2a1c82a9016d813d2c9145e479453502c332999d6f1e8b87facc8a955f6f2197cc29a1927a87ffd03da6
7
- data.tar.gz: a161e61578a2ba3b63e23add1724d67e5b4f05cfb4a795c5cf33542bddb1d210019150a75e7976ef3b11aa31a2f0002c5bc0167442ee65b2790da3482cbab5ab
6
+ metadata.gz: 2fac88101d8d8087cf436299a25be28a56e70305f28b2c15c43d0888e1b3da34bb6ca23683d7dca216ecc27b7fa32324645882a77ee87b76c7dc7ead85e81b87
7
+ data.tar.gz: 4692ca4f35efcce3f1069f6d6068c4db6e492f99be500f57c4c88bf2bdf57d31ca7215edc23f8cdc5d16e3213c4c1ff3fded90378cf71a653638253cc368c11d
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.8.4
2
+
3
+ * Support relative keys in mailers [#155](https://github.com/glebm/i18n-tasks/issues/155).
4
+
1
5
  ## 0.8.3
2
6
 
3
7
  * Fix regression: ActiveSupport < 4 support [#143](https://github.com/glebm/i18n-tasks/issues/143).
@@ -37,7 +37,7 @@ TEXT
37
37
  s.add_dependency 'activesupport'
38
38
  s.add_dependency 'easy_translate', '>= 0.5.0'
39
39
  s.add_dependency 'term-ansicolor'
40
- s.add_dependency 'terminal-table'
40
+ s.add_dependency 'terminal-table', '~> 1.4.5'
41
41
  s.add_dependency 'highline'
42
42
  s.add_dependency 'i18n'
43
43
  s.add_development_dependency 'axlsx', '~> 2.0'
@@ -24,12 +24,19 @@ module I18n
24
24
  end
25
25
 
26
26
 
27
+ require 'active_support/inflector'
27
28
  require 'active_support/core_ext/hash'
28
- require 'active_support/core_ext/string'
29
29
  require 'active_support/core_ext/array/access'
30
+ require 'active_support/core_ext/array/extract_options'
30
31
  require 'active_support/core_ext/module/delegation'
31
- require 'active_support/core_ext/object/try'
32
32
  require 'active_support/core_ext/object/blank'
33
+ begin
34
+ # activesupport >= 3
35
+ require 'active_support/core_ext/object/try'
36
+ rescue LoadError => _e
37
+ # activesupport ~> 2.3.2
38
+ require 'active_support/core_ext/try'
39
+ end
33
40
  require 'term/ansicolor'
34
41
  require 'erubis'
35
42
 
@@ -1,3 +1,4 @@
1
+ require 'i18n/tasks/command/dsl'
1
2
  require 'i18n/tasks/command/options/common'
2
3
  require 'i18n/tasks/command/options/locales'
3
4
  require 'i18n/tasks/command/options/data'
@@ -1,3 +1,5 @@
1
+ require 'i18n/tasks/command/collection'
2
+
1
3
  module I18n::Tasks
2
4
  module Command
3
5
  module Commands
@@ -3,9 +3,7 @@ module I18n::Tasks
3
3
  module DSL
4
4
  def self.included(base)
5
5
  base.module_eval do
6
- @dsl = HashWithIndifferentAccess.new { |h, k|
7
- h[k] = HashWithIndifferentAccess.new
8
- }
6
+ @dsl = Hash.new { |h, k| h[k] = {} }
9
7
  extend ClassMethods
10
8
  end
11
9
  end
@@ -1,3 +1,4 @@
1
+ require 'i18n/tasks/command/dsl'
1
2
 
2
3
  module I18n::Tasks
3
4
  module Command
@@ -10,11 +10,11 @@ module I18n::Tasks
10
10
  @data ||= begin
11
11
  data_config = (config[:data] || {}).with_indifferent_access
12
12
  data_config.merge!(base_locale: base_locale, locales: config[:locales])
13
- adapter_class = data_config[:adapter].presence || data_config[:class].presence || :file_system
13
+ adapter_class = data_config[:adapter].presence || data_config[:class].presence || 'file_system'
14
14
  adapter_class = adapter_class.to_s
15
- adapter_class = "I18n::Tasks::Data::#{adapter_class.camelize}" if adapter_class !~ /[A-Z]/
15
+ adapter_class = 'I18n::Tasks::Data::FileSystem' if adapter_class == 'file_system'
16
16
  data_config.except!(:adapter, :class)
17
- adapter_class.constantize.new data_config
17
+ ActiveSupport::Inflector.constantize(adapter_class).new data_config
18
18
  end
19
19
  end
20
20
 
@@ -122,13 +122,16 @@ module I18n::Tasks
122
122
  self.router = router_was
123
123
  end
124
124
 
125
+
126
+ ROUTER_NAME_ALIASES = {
127
+ 'conservative_router' => 'I18n::Tasks::Data::Router::ConservativeRouter',
128
+ 'pattern_router' => 'I18n::Tasks::Data::Router::PatternRouter'
129
+ }
125
130
  def router
126
131
  @router ||= begin
127
132
  name = @config[:router].presence || 'conservative_router'
128
- if name[0] != name[0].upcase
129
- name = "I18n::Tasks::Data::Router::#{name.classify}"
130
- end
131
- name.constantize.new(self, @config.merge(base_locale: base_locale, locales: locales))
133
+ name = ROUTER_NAME_ALIASES[name] || name
134
+ ActiveSupport::Inflector.constantize(name).new(self, @config.merge(base_locale: base_locale, locales: locales))
132
135
  end
133
136
  end
134
137
  attr_writer :router
@@ -128,7 +128,7 @@ module I18n::Tasks
128
128
  def set_each_value!(val_pattern, key_pattern = nil, &value_proc)
129
129
  value_proc ||= proc { |node|
130
130
  node_value = node.value
131
- human_key = node.key.to_s.humanize
131
+ human_key = ActiveSupport::Inflector.humanize(node.key.to_s)
132
132
  StringInterpolation.interpolate_soft(
133
133
  val_pattern,
134
134
  value: node_value,
@@ -47,7 +47,7 @@ module I18n::Tasks::Scanners
47
47
 
48
48
  def absolute_key(key, path, location)
49
49
  if key.start_with?('.')
50
- if controller_file?(path)
50
+ if controller_file?(path) || mailer_file?(path)
51
51
  absolutize_key(key, path, relative_roots, closest_method(location))
52
52
  else
53
53
  absolutize_key(key, path)
@@ -61,6 +61,10 @@ module I18n::Tasks::Scanners
61
61
  /controllers/.match(path)
62
62
  end
63
63
 
64
+ def mailer_file?(path)
65
+ /mailers/.match(path)
66
+ end
67
+
64
68
  def closest_method(location)
65
69
  method = File.readlines(location[:src_path], encoding: 'UTF-8').first(location[:line_num] - 1).reverse_each.find { |x| x=~ /\bdef\b/ }
66
70
  method &&= method.strip.sub(/^def\s*/, '').sub(/[\(\s;].*$/, '')
@@ -17,7 +17,7 @@ module I18n
17
17
  parts << part
18
18
  pos += part.length + 1
19
19
  if parts.length + 1 >= max
20
- parts << key.from(pos) unless pos == key.length
20
+ parts << key[pos..-1] unless pos == key.length
21
21
  break
22
22
  end
23
23
  end
@@ -22,7 +22,7 @@ module I18n::Tasks
22
22
  @scanner ||= begin
23
23
  search_config = (config[:search] || {}).with_indifferent_access
24
24
  class_name = search_config[:scanner] || '::I18n::Tasks::Scanners::PatternWithScopeScanner'
25
- class_name.constantize.new search_config
25
+ ActiveSupport::Inflector.constantize(class_name).new search_config
26
26
  end
27
27
  end
28
28
 
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  module I18n
3
3
  module Tasks
4
- VERSION = '0.8.3'
4
+ VERSION = '0.8.4'
5
5
  end
6
6
  end
@@ -36,6 +36,7 @@ search:
36
36
  relative_roots:
37
37
  - app/views
38
38
  - app/controllers
39
+ - app/mailers
39
40
 
40
41
 
41
42
  # do not report these keys ever
@@ -158,7 +158,7 @@ describe 'i18n-tasks' do
158
158
  }
159
159
  run_cmd 'add-missing', 'base'
160
160
  in_test_app_dir {
161
- expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['key']).to eq I18n.t('i18n_tasks.common.key')
161
+ expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['key']).to eq 'Key'
162
162
  expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'ES_TEXT'
163
163
  }
164
164
  end
@@ -55,5 +55,44 @@ describe 'Relative keys' do
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ context 'relative key in mailer' do
60
+ it 'works' do
61
+ key = scanner.absolutize_key(
62
+ '.subject',
63
+ 'app/mailers/user_mailer.rb',
64
+ %w(app/mailers),
65
+ 'welcome'
66
+ )
67
+
68
+ expect(key).to eq('user_mailer.welcome.subject')
69
+ end
70
+
71
+ context 'multiple words in mailer name' do
72
+ it 'works' do
73
+ key = scanner.absolutize_key(
74
+ '.subject',
75
+ 'app/mailers/admin_user_mailer.rb',
76
+ %w(app/mailers),
77
+ 'welcome'
78
+ )
79
+
80
+ expect(key).to eq('admin_user_mailer.welcome.subject')
81
+ end
82
+ end
83
+
84
+ context 'nested in module' do
85
+ it 'works' do
86
+ key = scanner.absolutize_key(
87
+ '.subject',
88
+ 'app/mailers/nested/user_mailer.rb',
89
+ %w(app/mailers),
90
+ 'welcome'
91
+ )
92
+
93
+ expect(key).to eq('nested.user_mailer.welcome.subject')
94
+ end
95
+ end
96
+ end
58
97
  end
59
98
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ require 'active_support/core_ext/kernel/reporting'
2
3
  module CaptureStd
3
4
  def capture_stderr
4
5
  err, $stderr = $stderr, StringIO.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: terminal-table
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.4.5
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.4.5
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: highline
85
85
  requirement: !ruby/object:Gem::Requirement