i18n-tasks 1.0.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 661d702b4ea3c0c936500d485c31873fcdc56933953c046de909e8299dfe961d
4
- data.tar.gz: b128f10c3112eac25dc5727181fb49700df7c8374f79db66e4ff8561b4f1320e
3
+ metadata.gz: adca7ca6bf65af74c2a4e88e30179281471f1b391a9dec1885031f6e4b5d104c
4
+ data.tar.gz: 82bfb0f4dd4d614fc93b34427e9e4d6aee2c2e3f9a9115d3b89bb1938edfeb8b
5
5
  SHA512:
6
- metadata.gz: a3d4ad6557ffbc2901f1b4cfa11c2b4560060eeaf4e8b429b3cdb2e7e4775c3a8985d47fa21d18b9a891c58f3a961ddc85538afc63d7d0125f8dda1a6a089d72
7
- data.tar.gz: b0bb3a3859d725f084d05f741484c5b6606ee2a52714b735315128a6f39c79062fb1f8a24aeb29d1f9fb3053424680a1df0d6a780b03cb2a9c3c68179dfe3347
6
+ metadata.gz: ac7dfdb7bcfa4ccf412b9afeb5d309d86d6a49dbbfe6c39d2128aff5e5cf8b1ee29cc8a7089975e1c0677c79c63985f19ebf6175010e9a7e21e02ebf2aca3323
7
+ data.tar.gz: f05bc85a3df41d6eb857fb3f52f20328093c28ee3595c5dc3acbbbab8a2dfd5462712052e6237b53cff2f53c5971f006dd5a840fc09987ef6b246d5a4b6fd214
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.0'
27
+ gem 'i18n-tasks', '~> 1.0.3'
28
28
  ```
29
29
 
30
30
  Copy the default [configuration file](#configuration):
@@ -223,7 +223,7 @@ See the full list of tasks with `i18n-tasks --help`.
223
223
 
224
224
  ### Features and limitations
225
225
 
226
- `i18n-tasks` uses an AST scanner for `.rb` files, and a regexp-based scanner for other files, such as `.haml`.
226
+ `i18n-tasks` uses an AST scanner for `.rb` and `.html.erb` files, and a regexp-based scanner for other files, such as `.haml`.
227
227
 
228
228
  #### Relative keys
229
229
 
@@ -9,7 +9,7 @@ module I18n::Tasks::Scanners
9
9
  include AST::Processor::Mixin
10
10
  def initialize
11
11
  super()
12
- @ruby_parser = LocalRubyParser.new
12
+ @ruby_parser = LocalRubyParser.new(ignore_blocks: true)
13
13
  @comments = []
14
14
  end
15
15
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'i18n/tasks/scanners/ruby_ast_scanner'
4
4
  require 'i18n/tasks/scanners/erb_ast_processor'
5
- require 'better_html'
5
+ require 'better_html/errors'
6
6
  require 'better_html/parser'
7
7
 
8
8
  module I18n::Tasks::Scanners
@@ -4,14 +4,23 @@ require 'parser/current'
4
4
 
5
5
  module I18n::Tasks::Scanners
6
6
  class LocalRubyParser
7
- def initialize
7
+ # ignore_blocks feature inspired by shopify/better-html
8
+ # https://github.com/Shopify/better-html/blob/087943ffd2a5877fa977d71532010b0c91239519/lib/better_html/test_helper/ruby_node.rb#L24
9
+ BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/.freeze
10
+
11
+ def initialize(ignore_blocks: false)
8
12
  @parser = ::Parser::CurrentRuby.new
13
+ @ignore_blocks = ignore_blocks
9
14
  end
10
15
 
11
16
  # Parse string and normalize location
12
17
  def parse(source, location: nil)
13
18
  buffer = ::Parser::Source::Buffer.new('(string)')
14
- buffer.source = source
19
+ buffer.source = if @ignore_blocks
20
+ source.sub(BLOCK_EXPR, '')
21
+ else
22
+ source
23
+ end
15
24
 
16
25
  @parser.reset
17
26
  ast, comments = @parser.parse_with_comments(buffer)
@@ -43,6 +52,8 @@ module I18n::Tasks::Scanners
43
52
  # @param local_location {Parser::Source::Map} Local location in the parsed string
44
53
  # @return {Parser::Source::Map}
45
54
  def updated_location(global_location, local_location)
55
+ return global_location if local_location.expression.nil?
56
+
46
57
  range = ::Parser::Source::Range.new(
47
58
  global_location.expression.source_buffer,
48
59
  global_location.expression.to_range.begin + local_location.expression.to_range.begin,
@@ -48,7 +48,7 @@ module I18n::Tasks
48
48
  # rubocop:enable Metrics/ParameterLists
49
49
 
50
50
  def inspect
51
- "Occurrence(#{@path}:#{@line_num}:#{@line_pos}:#{@pos}:#{@raw_key}:#{@default_arg}:#{@line})"
51
+ "Occurrence(#{@path}:#{@line_num}, line_pos: #{@line_pos}, pos: #{@pos}, raw_key: #{@raw_key}, default_arg: #{@default_arg}, line: #{@line})"
52
52
  end
53
53
 
54
54
  def ==(other)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Tasks
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.3'
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.0
4
+ version: 1.0.3
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-22 00:00:00.000000000 Z
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport