i18n-tasks 0.9.0.rc1 → 0.9.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -47
  3. data/bin/i18n-tasks +4 -0
  4. data/config/locales/en.yml +103 -103
  5. data/config/locales/ru.yml +1 -1
  6. data/i18n-tasks.gemspec +6 -5
  7. data/lib/i18n/tasks/cli.rb +10 -6
  8. data/lib/i18n/tasks/command/commander.rb +2 -2
  9. data/lib/i18n/tasks/command/commands/missing.rb +17 -5
  10. data/lib/i18n/tasks/command/option_parsers/locale.rb +8 -1
  11. data/lib/i18n/tasks/command_error.rb +1 -1
  12. data/lib/i18n/tasks/configuration.rb +12 -5
  13. data/lib/i18n/tasks/data.rb +5 -2
  14. data/lib/i18n/tasks/data/file_system_base.rb +7 -5
  15. data/lib/i18n/tasks/data/tree/siblings.rb +3 -3
  16. data/lib/i18n/tasks/data/tree/traversal.rb +9 -3
  17. data/lib/i18n/tasks/google_translation.rb +2 -2
  18. data/lib/i18n/tasks/key_pattern_matching.rb +9 -9
  19. data/lib/i18n/tasks/logging.rb +2 -2
  20. data/lib/i18n/tasks/missing_keys.rb +5 -5
  21. data/lib/i18n/tasks/scanners/file_scanner.rb +62 -0
  22. data/lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb +10 -2
  23. data/lib/i18n/tasks/scanners/files/file_finder.rb +3 -3
  24. data/lib/i18n/tasks/scanners/occurrence_from_position.rb +25 -0
  25. data/lib/i18n/tasks/scanners/pattern_scanner.rb +18 -62
  26. data/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb +3 -10
  27. data/lib/i18n/tasks/scanners/relative_keys.rb +28 -28
  28. data/lib/i18n/tasks/scanners/results/key_occurrences.rb +53 -0
  29. data/lib/i18n/tasks/scanners/results/occurrence.rb +59 -0
  30. data/lib/i18n/tasks/scanners/ruby_ast_call_finder.rb +62 -0
  31. data/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +193 -0
  32. data/lib/i18n/tasks/scanners/scanner.rb +3 -3
  33. data/lib/i18n/tasks/scanners/scanner_multiplexer.rb +2 -12
  34. data/lib/i18n/tasks/scanners/slim_temple_scanner.rb +24 -0
  35. data/lib/i18n/tasks/scanners/temple_scanner.rb +33 -0
  36. data/lib/i18n/tasks/used_keys.rb +67 -43
  37. data/lib/i18n/tasks/version.rb +1 -1
  38. data/templates/config/i18n-tasks.yml +2 -5
  39. metadata +46 -108
  40. data/.coveralls.yml +0 -1
  41. data/.gitattributes +0 -2
  42. data/.gitignore +0 -35
  43. data/.travis.yml +0 -18
  44. data/CHANGES.md +0 -351
  45. data/Gemfile +0 -13
  46. data/config/i18n-tasks.yml +0 -22
  47. data/lib/i18n/tasks/scanners/key_occurrences.rb +0 -35
  48. data/lib/i18n/tasks/scanners/occurence.rb +0 -50
  49. data/spec/commands/data_commands_spec.rb +0 -38
  50. data/spec/commands/tree_commands_spec.rb +0 -69
  51. data/spec/conservative_router_spec.rb +0 -50
  52. data/spec/file_system_data_spec.rb +0 -101
  53. data/spec/fixtures/app/assets/javascripts/application.js +0 -3
  54. data/spec/fixtures/app/controllers/events_controller.rb +0 -38
  55. data/spec/fixtures/app/views/index.html.slim +0 -29
  56. data/spec/fixtures/app/views/relative/index.html.slim +0 -3
  57. data/spec/fixtures/app/views/usages.html.slim +0 -2
  58. data/spec/fixtures/config/i18n-tasks.yml +0 -63
  59. data/spec/fixtures/lib/test_i18n_plugin.rb +0 -12
  60. data/spec/google_translate_spec.rb +0 -69
  61. data/spec/i18n_spec.rb +0 -17
  62. data/spec/i18n_tasks_spec.rb +0 -302
  63. data/spec/key_pattern_matching_spec.rb +0 -63
  64. data/spec/locale_pathname_spec.rb +0 -24
  65. data/spec/locale_tree/siblings_spec.rb +0 -115
  66. data/spec/pattern_scanner_spec.rb +0 -57
  67. data/spec/plural_keys_spec.rb +0 -44
  68. data/spec/readme_spec.rb +0 -9
  69. data/spec/relative_keys_spec.rb +0 -103
  70. data/spec/scanners/files/caching_file_finder_provider_spec.rb +0 -18
  71. data/spec/scanners/files/caching_file_finder_spec.rb +0 -39
  72. data/spec/scanners/files/caching_file_reader_spec.rb +0 -18
  73. data/spec/scanners/files/file_finder_spec.rb +0 -52
  74. data/spec/scanners/files/file_reader_spec.rb +0 -15
  75. data/spec/scanners/scanner_multiplexer_spec.rb +0 -26
  76. data/spec/spec_helper.rb +0 -24
  77. data/spec/split_key_spec.rb +0 -33
  78. data/spec/support/capture_std.rb +0 -22
  79. data/spec/support/fixtures.rb +0 -14
  80. data/spec/support/i18n_tasks_output_matcher.rb +0 -37
  81. data/spec/support/key_pattern_matcher.rb +0 -7
  82. data/spec/support/keys_and_occurrences.rb +0 -27
  83. data/spec/support/test_codebase.rb +0 -82
  84. data/spec/support/trees.rb +0 -20
  85. data/spec/used_keys_spec.rb +0 -74
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
- require 'i18n/tasks/scanners/files/file_reader'
3
-
4
- RSpec.describe 'FileReader' do
5
- describe '#read_file' do
6
- around do |ex|
7
- TestCodebase.setup('test.txt' => 'test')
8
- TestCodebase.in_test_app_dir { ex.call }
9
- TestCodebase.teardown
10
- end
11
- it 'reads the file' do
12
- expect(I18n::Tasks::Scanners::Files::FileReader.new.read_file('test.txt')).to eq('test')
13
- end
14
- end
15
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'i18n/tasks/scanners/scanner_multiplexer'
3
-
4
- RSpec.describe 'ScannerMultiplexer' do
5
- describe '#keys' do
6
- let(:key_a) { make_key_occurrences 'key.a', [{path: 'a'}] }
7
- let(:key_b_1) { make_key_occurrences 'key.b', [{path: 'b1'}] }
8
- let(:key_b_2) { make_key_occurrences 'key.b', [{path: 'b2'}] }
9
- let(:key_c) { make_key_occurrences 'key.c', [{path: 'c'}] }
10
-
11
- scanner_mock = Struct.new(:keys)
12
- let(:scanner_one) { scanner_mock.new([key_a, key_b_1]) }
13
- let(:scanner_two) { scanner_mock.new([key_b_2, key_c]) }
14
-
15
- let(:expected_key_occurrences) {
16
- [key_a,
17
- I18n::Tasks::Scanners::KeyOccurrences.new(key: 'key.b', occurrences: key_b_1.occurrences + key_b_2.occurrences),
18
- key_c]
19
- }
20
-
21
- it 'returns the merged results' do
22
- scanner_multiplexer = I18n::Tasks::Scanners::ScannerMultiplexer.new(scanners: [scanner_one, scanner_two])
23
- expect(scanner_multiplexer.keys).to eq expected_key_occurrences
24
- end
25
- end
26
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +0,0 @@
1
- ENV['RAILS_ENV'] = ENV['RAKE_ENV'] = 'test'
2
-
3
- if ENV['TRAVIS'] && !(defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx')
4
- require 'codeclimate-test-reporter'
5
- CodeClimate::TestReporter.start
6
- end
7
-
8
- $: << File.expand_path('../lib', __FILE__)
9
-
10
- require 'i18n/tasks'
11
- require 'rake'
12
-
13
- require 'term/ansicolor'
14
- Term::ANSIColor::coloring = false
15
-
16
- Dir['spec/support/**/*.rb'].each { |f| require "./#{f}" }
17
-
18
- RSpec.configure do |config|
19
- config.expose_dsl_globally = false
20
- config.include FixturesSupport
21
- config.include CaptureStd
22
- config.include Trees
23
- config.include KeysAndOccurrences
24
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'SplitKey' do
4
- include ::I18n::Tasks::SplitKey
5
-
6
- [['', %w()],
7
- ['a', %w(a)],
8
- ['a.b', %w(a b)],
9
- ['a.b.', %w(a b)],
10
- ['a.b.c', %w(a b c)],
11
- ['a.#{b.c}', %w(a #{b.c})],
12
- ['a.#{b.c}.', %w(a #{b.c})],
13
- ['a.#{b.c}.d', %w(a #{b.c} d)],
14
- ['a.#{b.c}.d.[e.f]', %w(a #{b.c} d [e.f])],
15
- ].each do |(arg, ret)|
16
- it "#{arg} is split into #{ret.inspect}" do
17
- expect(split_key arg).to eq(ret)
18
- end
19
- end
20
-
21
- it 'limits results to second argument' do
22
- expect(split_key 'a.b.c', 1).to eq(['a.b.c'])
23
- expect(split_key 'a.b.c', 2).to eq(['a', 'b.c'])
24
- expect(split_key 'a.b.c.', 2).to eq(['a', 'b.c.'])
25
- expect(split_key 'a.b.c.d.e.f', 4).to eq(['a', 'b', 'c', 'd.e.f'])
26
- end
27
-
28
- it 'last part' do
29
- expect(last_key_part 'a.b.c').to eq('c')
30
- expect(last_key_part 'a').to eq('a')
31
- expect(last_key_part 'a.b.c.d').to eq('d')
32
- end
33
- end
@@ -1,22 +0,0 @@
1
- require 'active_support/core_ext/kernel/reporting'
2
- module CaptureStd
3
- def capture_stderr
4
- err, $stderr = $stderr, StringIO.new
5
- yield
6
- $stderr.string
7
- ensure
8
- $stderr = err
9
- end
10
-
11
- def capture_stdout
12
- out, $stdout = $stdout, StringIO.new
13
- yield
14
- $stdout.string
15
- ensure
16
- $stdout = out
17
- end
18
-
19
- def silence_stderr(&block)
20
- silence_stream($stderr, &block)
21
- end
22
- end
@@ -1,14 +0,0 @@
1
- # quick'n'dirty fixture loader
2
- module FixturesSupport
3
- def fixtures_contents
4
- @fixtures_contents ||= begin
5
- fixtures_path = 'spec/fixtures'
6
- Dir.glob("#{fixtures_path}/**/*").inject({}) { |h, path|
7
- next h if File.directory?(path)
8
- h[path[fixtures_path.length + 1..-1]] = Pathname.new(path).read
9
- h
10
- }
11
- end
12
- end
13
- end
14
-
@@ -1,37 +0,0 @@
1
- RSpec::Matchers.define :be_i18n_keys do |expected|
2
- def locale_re
3
- /^\w{2}\b/
4
- end
5
-
6
- def extract_keys(actual)
7
- actual = Term::ANSIColor.uncolor(actual).split("\n").map(&:presence).compact
8
- actual = actual[3..-2]
9
- actual = actual.map { |row|
10
- row[1..-1].gsub(/(?:\s+|^)\|(?:\s+|$)/, '|').gsub(/\s+/, ' ').strip.split(/\s*\|\s*/)
11
- }.compact
12
- return [] if actual.empty?
13
- locale_col = 0
14
- key_col = 1
15
- actual.map { |row|
16
- key = [row[locale_col], row[key_col]].map(&:presence).compact.join('.')
17
- key = key[0..-2] if key.end_with?(':')
18
- key
19
- }.compact
20
- end
21
-
22
- match do |actual|
23
- expect(extract_keys(actual).sort).to eq(expected.sort)
24
- end
25
-
26
- failure_message do |actual|
27
- e = expected.sort
28
- a = extract_keys(actual).sort
29
-
30
- <<-MSG.strip
31
- Expected #{e}, but had #{a}. Diff:
32
-
33
- missing: #{e-a}
34
- extra: #{a-e}
35
- MSG
36
- end
37
- end
@@ -1,7 +0,0 @@
1
- RSpec::Matchers.define :match_key do |key|
2
- include I18n::Tasks::KeyPatternMatching
3
-
4
- match do |pattern|
5
- expect(compile_key_pattern(pattern)).to match(key)
6
- end
7
- end
@@ -1,27 +0,0 @@
1
- module KeysAndOccurrences
2
- def make_occurrence(path: '', line: '', pos: 1, line_pos: 1, line_num: 1)
3
- ::I18n::Tasks::Scanners::Occurrence.new(path: path, line: line, pos: pos, line_pos: line_pos, line_num: line_num)
4
- end
5
-
6
- def make_occurrences(occurrences)
7
- occurrences.map { |attr| make_occurrence(attr) }
8
- end
9
-
10
- def make_key_occurrences(key, occurrences)
11
- ::I18n::Tasks::Scanners::KeyOccurrences.new(key: key, occurrences: make_occurrences(occurrences))
12
- end
13
-
14
- # adjust position to account for \r on Windows
15
- def adjust_occurrences(data)
16
- if Gem.win_platform?
17
- data = data.dup
18
- data[:occurrences].map! { |occ| adjust_occurrence occ }
19
- end
20
- data
21
- end
22
-
23
- # adjust position to account for \r on Windows
24
- def adjust_occurrence(occurrence)
25
- occurrence.dup.tap { |o| o.instance_variable_set(:@pos, o.pos + o.line_num - 1) }
26
- end
27
- end
@@ -1,82 +0,0 @@
1
- require 'fileutils'
2
- require 'yaml'
3
- require_relative 'capture_std'
4
- require 'i18n/tasks/commands'
5
- require 'i18n/tasks/cli'
6
-
7
- module TestCodebase
8
- include CaptureStd
9
- extend self
10
- AT = 'tmp/test_codebase'
11
-
12
- def i18n_task(*args)
13
- in_test_app_dir do
14
- ::I18n::Tasks::BaseTask.new(*args)
15
- end
16
- end
17
-
18
- def run_cmd(name, *args)
19
- capture_stdout { capture_stderr { in_test_app_dir {
20
- run_cli(name, *args)
21
- } } }
22
- end
23
-
24
- def run_cmd_capture_stdout_and_result(name, *args)
25
- result = nil
26
- out = capture_stdout { capture_stderr { in_test_app_dir {
27
- result = run_cli(name, *args)
28
- } } }
29
- [out, result]
30
- end
31
-
32
- def run_cmd_capture_stderr(name, *args)
33
- capture_stderr { capture_stdout { in_test_app_dir {
34
- run_cli(name, *args)
35
- } } }
36
- end
37
-
38
- def run_cli(name, *args)
39
- i18n_cli.run([name, *args])
40
- end
41
-
42
- def i18n_cli
43
- in_test_app_dir { ::I18n::Tasks::CLI.new }
44
- end
45
-
46
- def setup(files = {})
47
- FileUtils.mkdir_p AT
48
- in_test_app_dir do
49
- files.each do |path, content|
50
- FileUtils.mkdir_p File.dirname(path)
51
- File.open(path, 'w') { |f| f.write(content) }
52
- end
53
- end
54
- end
55
-
56
- def teardown
57
- FileUtils.rm_rf AT
58
- end
59
-
60
- def rake_result(task, *args)
61
- in_test_app_dir {
62
- rake_task = Rake::Task[task]
63
- rake_task.reenable
64
- capture_stdout { rake_task.invoke(*args) }
65
- }
66
- end
67
-
68
- def in_test_app_dir
69
- return yield if @in_dir
70
- begin
71
- pwd = Dir.pwd
72
- Dir.chdir AT
73
- @in_dir = true
74
- yield
75
- ensure
76
- Dir.chdir pwd
77
- @in_dir = false
78
- end
79
- end
80
- end
81
-
82
-
@@ -1,20 +0,0 @@
1
- module Trees
2
- def expect_node_key_data(node, key, data)
3
- expect(node.full_key(root: false)).to eq key
4
- expect(node.data).to eq adjust_occurrences(data)
5
- end
6
-
7
- def build_tree(hash)
8
- I18n::Tasks::Data::Tree::Siblings.from_nested_hash(hash)
9
- end
10
-
11
- def build_node(attr = {})
12
- raise 'invalid node (more than 1 root)' if attr.size > 1
13
- key, value = attr.first
14
- I18n::Tasks::Data::Tree::Node.from_key_value(key, value)
15
- end
16
-
17
- def new_node(attr = {})
18
- I18n::Tasks::Data::Tree::Node.new(attr)
19
- end
20
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'UsedKeys' do
4
- let!(:task) { I18n::Tasks::BaseTask.new }
5
- let(:file_name) { 'a.html.slim' }
6
- let(:file_content) do
7
- <<-SLIM
8
- div = t 'a'
9
- p = t 'a'
10
- h1 = t 'b'
11
- SLIM
12
- end
13
-
14
- around do |ex|
15
- task.config[:search] = {paths: [file_name]}
16
- TestCodebase.setup(file_name => file_content)
17
- TestCodebase.in_test_app_dir { ex.run }
18
- TestCodebase.teardown
19
- end
20
-
21
- it '#used_keys' do
22
- used = task.used_tree
23
- leaves = used.leaves.to_a
24
- expect(leaves.size).to eq 2
25
- expect_node_key_data(
26
- leaves[0],
27
- 'a',
28
- occurrences: make_occurrences(
29
- [{path: 'a.html.slim', pos: 6, line_num: 1, line_pos: 7, line: "div = t 'a'"},
30
- {path: 'a.html.slim', pos: 18, line_num: 2, line_pos: 7, line: " p = t 'a'"}])
31
- )
32
-
33
- expect_node_key_data(
34
- leaves[1],
35
- 'b',
36
- occurrences: make_occurrences(
37
- [{path: 'a.html.slim', pos: 29, line_num: 3, line_pos: 6, line: "h1 = t 'b'"}])
38
- )
39
- end
40
-
41
- it '#used_keys(key_filter: "b*")' do
42
- used_keys = task.used_tree(key_filter: 'b*')
43
- expect(used_keys.size).to eq 1
44
- expect_node_key_data(
45
- used_keys.leaves.first,
46
- 'b',
47
- occurrences: make_occurrences(
48
- [{path: 'a.html.slim', pos: 29, line_num: 3, line_pos: 6, line: "h1 = t 'b'"}])
49
- )
50
- end
51
-
52
- describe 'when input is haml' do
53
- let(:file_name) { 'a.html.haml' }
54
- let(:file_content) do
55
- <<-HAML
56
- #first{ title: t('a') }
57
- .second{ title: t('a') }
58
- - # t('a') in a comment is ignored
59
- HAML
60
- end
61
-
62
- it '#used_keys(source_occurences: true)' do
63
- used_keys = task.used_tree
64
- expect(used_keys.size).to eq 1
65
- expect_node_key_data(
66
- used_keys.leaves.first,
67
- 'a',
68
- occurrences: make_occurrences(
69
- [{path: 'a.html.haml', pos: 15, line_num: 1, line_pos: 16, line: "#first{ title: t('a') }"},
70
- {path: 'a.html.haml', pos: 40, line_num: 2, line_pos: 17, line: ".second{ title: t('a') }"}])
71
- )
72
- end
73
- end
74
- end