i18n-tasks 1.0.3 → 1.0.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
  SHA256:
3
- metadata.gz: adca7ca6bf65af74c2a4e88e30179281471f1b391a9dec1885031f6e4b5d104c
4
- data.tar.gz: 82bfb0f4dd4d614fc93b34427e9e4d6aee2c2e3f9a9115d3b89bb1938edfeb8b
3
+ metadata.gz: 5006a01bb4cc0233b564962b0260a626c0985b9e787e234d95a8176c93716d94
4
+ data.tar.gz: a996c445790d6f679e17d77b241769d62fb6ee334af7bfa65f622b0c4b6b4864
5
5
  SHA512:
6
- metadata.gz: ac7dfdb7bcfa4ccf412b9afeb5d309d86d6a49dbbfe6c39d2128aff5e5cf8b1ee29cc8a7089975e1c0677c79c63985f19ebf6175010e9a7e21e02ebf2aca3323
7
- data.tar.gz: f05bc85a3df41d6eb857fb3f52f20328093c28ee3595c5dc3acbbbab8a2dfd5462712052e6237b53cff2f53c5971f006dd5a840fc09987ef6b246d5a4b6fd214
6
+ metadata.gz: 26c74331f3f32be4c8fbb49c16b308d6549f75eada577c2a589b0897591607d29a92d535a3a680d93957ada6a402ecafe87b923c54ef5563bdad7ec09f3949ac
7
+ data.tar.gz: 792b07d6e3e8b90d15a2582c509b817189051846f9a1c520b0fb78a44aaa5c166def08c7819f204b3685d6d86a27f858e6c4a8ae0516c6305177a7c53217490b
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', '~> 1.0.3'
27
+ gem 'i18n-tasks', '~> 1.0.4'
28
28
  ```
29
29
 
30
30
  Copy the default [configuration file](#configuration):
@@ -2,22 +2,26 @@
2
2
 
3
3
  module I18n::Tasks
4
4
  module Interpolations
5
- VARIABLE_REGEX = /%{[^}]+}/.freeze
5
+ class << self
6
+ attr_accessor :variable_regex
7
+ end
8
+ @variable_regex = /%{[^}]+}/.freeze
6
9
 
7
10
  def inconsistent_interpolations(locales: nil, base_locale: nil) # rubocop:disable Metrics/AbcSize
8
11
  locales ||= self.locales
9
12
  base_locale ||= self.base_locale
10
13
  result = empty_forest
14
+ variable_regex = I18n::Tasks::Interpolations.variable_regex
11
15
 
12
16
  data[base_locale].key_values.each do |key, value|
13
17
  next if !value.is_a?(String) || ignore_key?(key, :inconsistent_interpolations)
14
18
 
15
- base_vars = Set.new(value.scan(VARIABLE_REGEX))
19
+ base_vars = Set.new(value.scan(variable_regex))
16
20
  (locales - [base_locale]).each do |current_locale|
17
21
  node = data[current_locale].first.children[key]
18
22
  next unless node&.value.is_a?(String)
19
23
 
20
- if base_vars != Set.new(node.value.scan(VARIABLE_REGEX))
24
+ if base_vars != Set.new(node.value.scan(variable_regex))
21
25
  result.merge!(node.walk_to_root.reduce(nil) { |c, p| [p.derive(children: c)] })
22
26
  end
23
27
  end
@@ -35,7 +35,10 @@ module I18n::Tasks::Scanners
35
35
  node
36
36
  end
37
37
 
38
+ # @param node [::Parser::AST::Node]
39
+ # @return [::Parser::AST::Node]
38
40
  def handler_missing(node)
41
+ node = transform_misparsed_comment(node)
39
42
  node.updated(
40
43
  nil,
41
44
  node.children.map { |child| node?(child) ? process(child) : child }
@@ -44,6 +47,35 @@ module I18n::Tasks::Scanners
44
47
 
45
48
  private
46
49
 
50
+ # Works around incorrect handling of comments of the form:
51
+ # <%# ... #>
52
+ # (no space between % and #)
53
+ #
54
+ # With a space the AST is:
55
+ #
56
+ # s(:erb, nil, nil,
57
+ # s(:code, " # this should not fail: ' "), nil)
58
+ #
59
+ # Without a space the AST is:
60
+ #
61
+ # s(:erb,
62
+ # s(:indicator, "#"), nil,
63
+ # s(:code, " this should not fail: ' "), nil)
64
+ # @param node [::Parser::AST::Node]
65
+ # @return [::Parser::AST::Node]
66
+ def transform_misparsed_comment(node)
67
+ return node unless node.type == :erb && node.children.size == 4 &&
68
+ node.children[0]&.type == :indicator && node.children[0].children[0] == "#" &&
69
+ node.children[1].nil? &&
70
+ node.children[2]&.type == :code &&
71
+ node.children[3].nil?
72
+ code_node = node.children[2]
73
+ node.updated(
74
+ nil,
75
+ [nil, nil, code_node.updated(nil, ["##{code_node.children[0]}"]), nil]
76
+ )
77
+ end
78
+
47
79
  def node?(node)
48
80
  node.is_a?(::Parser::AST::Node)
49
81
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Tasks
5
- VERSION = '1.0.3'
5
+ VERSION = '1.0.4'
6
6
  end
7
7
  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: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-24 00:00:00.000000000 Z
11
+ date: 2022-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport