i18n-tasks 0.9.8 → 0.9.9

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: d6e30b4e85fe299dbf8f89391c84f5dea2d242b2
4
- data.tar.gz: 9f6d31de1c84187fbad5e929c36416857f66f6e5
3
+ metadata.gz: 264a1871764cc205f99b56f5c303f6b174d16ee8
4
+ data.tar.gz: c7431a8401c9cc313c67ea03b276b627e9c950f3
5
5
  SHA512:
6
- metadata.gz: a3602fac64546ce66b2b500c3f2e010f01458e1cbd0ff708cbd5e329cca144574a47003ccb8533441e033de579147fbd00c6cb84f90c509720228d2a5e407f53
7
- data.tar.gz: b32c4925376a24e28cf1882d1e10168374e1c8770e3e7b43028c9820a11a2b2e59515b2b260fe4fdd03462789b0710528c779c7316155df214e11bfe75d1c8ee
6
+ metadata.gz: 3d5db9a5e118f6c410aa43b263835b160c101f615fe56d9fedc269b0269f5458d7398d034fdc895cd6f38e1f26eb04ecea998b1fa6317d01c745348040458a83
7
+ data.tar.gz: 654a287a7ffd39c309c75e9ec0456ad28f2ebac32ecf112a7e3adbcd757367a7afe092b6ebb7497f03a013471718807b1b69cb2aa7157b06f261b3a0eaab8bc6
data/README.md CHANGED
@@ -24,7 +24,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
24
24
  Add i18n-tasks to the Gemfile:
25
25
 
26
26
  ```ruby
27
- gem 'i18n-tasks', '~> 0.9.8'
27
+ gem 'i18n-tasks', '~> 0.9.9'
28
28
  ```
29
29
 
30
30
  Copy the default [configuration file](#configuration):
@@ -369,13 +369,13 @@ Custom tasks can be added easily, see the examples [on the wiki](https://github.
369
369
 
370
370
  [MIT license]: /LICENSE.txt
371
371
  [travis]: https://travis-ci.org/glebm/i18n-tasks
372
- [badge-travis]: http://img.shields.io/travis/glebm/i18n-tasks.svg
372
+ [badge-travis]: https://img.shields.io/travis/glebm/i18n-tasks.svg
373
373
  [coverage]: https://codeclimate.com/github/glebm/i18n-tasks
374
374
  [badge-coverage]: https://img.shields.io/codeclimate/coverage/github/glebm/i18n-tasks.svg
375
375
  [gemnasium]: https://gemnasium.com/glebm/i18n-tasks
376
376
  [badge-gemnasium]: https://gemnasium.com/glebm/i18n-tasks.svg
377
377
  [code-climate]: https://codeclimate.com/github/glebm/i18n-tasks
378
- [badge-code-climate]: http://img.shields.io/codeclimate/github/glebm/i18n-tasks.svg
378
+ [badge-code-climate]: https://img.shields.io/codeclimate/github/glebm/i18n-tasks.svg
379
379
  [config]: https://github.com/glebm/i18n-tasks/blob/master/templates/config/i18n-tasks.yml
380
380
  [wiki]: https://github.com/glebm/i18n-tasks/wiki "i18n-tasks wiki"
381
381
  [i18n-gem]: https://github.com/svenfuchs/i18n "svenfuchs/i18n on Github"
@@ -13,23 +13,21 @@ class I18n::Tasks::CLI
13
13
  def initialize; end
14
14
 
15
15
  def start(argv)
16
- I18n.with_locale(base_task.internal_locale) do
17
- auto_output_coloring do
16
+ auto_output_coloring do
17
+ begin
18
+ exit 1 if run(argv) == :exit_1
19
+ rescue OptionParser::ParseError => e
20
+ error e.message, 64
21
+ rescue I18n::Tasks::CommandError => e
18
22
  begin
19
- exit 1 if run(argv) == :exit_1
20
- rescue OptionParser::ParseError => e
21
- error e.message, 64
22
- rescue I18n::Tasks::CommandError => e
23
- begin
24
- error e.message, 78
25
- ensure
26
- log_verbose e.backtrace * "\n"
27
- end
28
- rescue Errno::EPIPE
29
- # ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
30
- # i18n-tasks missing | head
31
- exit 1
23
+ error e.message, 78
24
+ ensure
25
+ log_verbose e.backtrace * "\n"
32
26
  end
27
+ rescue Errno::EPIPE
28
+ # ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
29
+ # i18n-tasks missing | head
30
+ exit 1
33
31
  end
34
32
  end
35
33
  rescue ExecutionError => e
@@ -37,8 +35,10 @@ class I18n::Tasks::CLI
37
35
  end
38
36
 
39
37
  def run(argv)
40
- name, *options = parse!(argv.dup)
41
- context.run(name, *options)
38
+ I18n.with_locale(base_task.internal_locale) do
39
+ name, *options = parse!(argv.dup)
40
+ context.run(name, *options)
41
+ end
42
42
  end
43
43
 
44
44
  def context
@@ -88,7 +88,7 @@ module I18n::Tasks
88
88
  @available_locales ||= begin
89
89
  locales = Set.new
90
90
  Array(config[:read]).map do |pattern|
91
- [pattern, Dir.glob(pattern % { locale: '*' })] if pattern.include?('%{locale}')
91
+ [pattern, Dir.glob(format(pattern, locale: '*'))] if pattern.include?('%{locale}')
92
92
  end.compact.each do |pattern, paths|
93
93
  p = pattern.gsub('\\', '\\\\').gsub('/', '\/').gsub('.', '\.')
94
94
  p = p.gsub(/(\*+)/) { Regexp.last_match(1) == '**' ? '.*' : '[^/]*?' }.gsub('%{locale}', '([^/.]+)')
@@ -138,7 +138,7 @@ module I18n::Tasks
138
138
 
139
139
  def read_locale(locale)
140
140
  Array(config[:read]).map do |path|
141
- Dir.glob path % { locale: locale }
141
+ Dir.glob format(path, locale: locale)
142
142
  end.reduce(:+).map do |path|
143
143
  [path.freeze, load_file(path) || {}]
144
144
  end.map do |path, data|
@@ -32,7 +32,7 @@ module I18n::Tasks
32
32
  pattern, path = routes.detect { |route| route[0] =~ key }
33
33
  if pattern
34
34
  key_match = $~
35
- path = path % { locale: locale }
35
+ path = format(path, locale: locale)
36
36
  path.gsub!(/\\\d+/) { |m| key_match[m[1..-1].to_i] }
37
37
  (out[path] ||= Set.new) << "#{locale}.#{key}"
38
38
  else
@@ -2,6 +2,9 @@
2
2
  module I18n::Tasks::Logging
3
3
  module_function
4
4
 
5
+ MUTEX = Mutex.new
6
+ PROGRAM_NAME = File.basename($PROGRAM_NAME)
7
+
5
8
  def warn_deprecated(message)
6
9
  log_stderr Term::ANSIColor.yellow Term::ANSIColor.bold "#{program_name}: [DEPRECATED] #{message}"
7
10
  end
@@ -21,10 +24,15 @@ module I18n::Tasks::Logging
21
24
  end
22
25
 
23
26
  def log_stderr(*args)
24
- $stderr.puts(*args)
27
+ MUTEX.synchronize do
28
+ # 1. We don't want output from different threads to get intermixed.
29
+ # 2. StringIO is currently not thread-safe (blows up) on JRuby:
30
+ # https://github.com/jruby/jruby/issues/4417
31
+ $stderr.puts(*args)
32
+ end
25
33
  end
26
34
 
27
35
  def program_name
28
- @program_name ||= File.basename($PROGRAM_NAME)
36
+ PROGRAM_NAME
29
37
  end
30
38
  end
@@ -39,7 +39,7 @@ module I18n::Tasks::Scanners
39
39
  matches[:key] = strip_literal(matches[:key])
40
40
  next unless valid_key?(matches[:key])
41
41
  end
42
- result << [absolute_key(key % matches, path),
42
+ result << [absolute_key(format(key, matches), path),
43
43
  occurrence_from_position(path, text, match.offset(0).first)]
44
44
  end
45
45
  result
@@ -52,7 +52,7 @@ module I18n::Tasks::Scanners
52
52
 
53
53
  def configure_patterns(patterns)
54
54
  patterns.map do |(pattern, key)|
55
- [pattern.is_a?(Regexp) ? pattern : Regexp.new(pattern % { key: KEY_GROUP }), key]
55
+ [pattern.is_a?(Regexp) ? pattern : Regexp.new(format(pattern, key: KEY_GROUP)), key]
56
56
  end
57
57
  end
58
58
  end
@@ -23,18 +23,14 @@ module I18n::Tasks::Scanners
23
23
  key = super
24
24
  scope = match[1]
25
25
  if scope
26
- scope_ns = scope.gsub(/[\[\]\s]+/, '').split(',').map { |arg| strip_literal(arg) } * '.'
27
- "#{scope_ns}.#{key}"
26
+ scope_parts = extract_literal_or_array_of_literals(scope)
27
+ return nil if scope_parts.nil? || scope_parts.empty?
28
+ "#{scope_parts.join('.')}.#{key}"
28
29
  else
29
30
  key unless match[0] =~ /\A\w/
30
31
  end
31
32
  end
32
33
 
33
- # also parse expressions with literals
34
- def literal_re
35
- /(?: (?: #{super} ) | #{expr_re} )/x
36
- end
37
-
38
34
  # strip literals, convert expressions to #{interpolations}
39
35
  def strip_literal(val)
40
36
  if val =~ /\A\w/
@@ -49,7 +45,7 @@ module I18n::Tasks::Scanners
49
45
  /(?:
50
46
  :scope\s*=>\s* | (?# :scope => :home )
51
47
  scope:\s* (?# scope: :home )
52
- ) (#{array_or_one_literal_re})/x
48
+ ) ([^\n]*)/x
53
49
  end
54
50
 
55
51
  # match code expression
@@ -59,10 +55,40 @@ module I18n::Tasks::Scanners
59
55
  /[\w():"'.\s]+/x
60
56
  end
61
57
 
62
- # match +el+ or array of +el+
63
- def array_or_one_literal_re(el = literal_re)
64
- /#{el} |
65
- \[\s* (?:#{el}\s*,\s*)* #{el} \s*\]/x
58
+ # extract literal or array of literals
59
+ # returns nil on any other input
60
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
61
+ def extract_literal_or_array_of_literals(s)
62
+ literals = []
63
+ braces_stack = []
64
+ acc = []
65
+ consume_literal = proc do
66
+ acc_str = acc.join
67
+ if acc_str =~ literal_re
68
+ literals << strip_literal(acc_str)
69
+ acc = []
70
+ else
71
+ return nil
72
+ end
73
+ end
74
+ s.each_char.with_index do |c, i|
75
+ if c == '['
76
+ return nil unless braces_stack.empty?
77
+ braces_stack.push(i)
78
+ elsif c == ']'
79
+ break
80
+ elsif c == ','
81
+ consume_literal.call
82
+ break if braces_stack.empty?
83
+ elsif c =~ VALID_KEY_CHARS || /['":]/ =~ c
84
+ acc << c
85
+ elsif c != ' '
86
+ return nil
87
+ end
88
+ end
89
+ consume_literal.call unless acc.empty?
90
+ literals
66
91
  end
92
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
67
93
  end
68
94
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module I18n
3
3
  module Tasks
4
- VERSION = '0.9.8'
4
+ VERSION = '0.9.9'
5
5
  end
6
6
  end
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.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-27 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport