i18n-tasks 0.4.5 → 0.5.0
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 +4 -4
- data/.travis.yml +0 -4
- data/CHANGES.md +7 -0
- data/README.md +10 -14
- data/i18n-tasks.gemspec +1 -1
- data/lib/i18n/tasks.rb +0 -2
- data/lib/i18n/tasks/base_task.rb +4 -2
- data/lib/i18n/tasks/commands.rb +14 -14
- data/lib/i18n/tasks/configuration.rb +10 -2
- data/lib/i18n/tasks/console_context.rb +73 -0
- data/lib/i18n/tasks/data.rb +0 -47
- data/lib/i18n/tasks/data/adapter/yaml_adapter.rb +6 -1
- data/lib/i18n/tasks/data/file_system_base.rb +1 -1
- data/lib/i18n/tasks/data/router/conservative_router.rb +5 -5
- data/lib/i18n/tasks/data/router/pattern_router.rb +2 -2
- data/lib/i18n/tasks/data/tree/node.rb +47 -36
- data/lib/i18n/tasks/data/tree/nodes.rb +0 -4
- data/lib/i18n/tasks/data/tree/siblings.rb +54 -9
- data/lib/i18n/tasks/data/tree/traversal.rb +62 -23
- data/lib/i18n/tasks/fill_tasks.rb +29 -21
- data/lib/i18n/tasks/ignore_keys.rb +1 -1
- data/lib/i18n/tasks/key_pattern_matching.rb +17 -0
- data/lib/i18n/tasks/missing_keys.rb +39 -44
- data/lib/i18n/tasks/plural_keys.rb +14 -1
- data/lib/i18n/tasks/reports/base.rb +28 -8
- data/lib/i18n/tasks/reports/spreadsheet.rb +9 -8
- data/lib/i18n/tasks/reports/terminal.rb +33 -29
- data/lib/i18n/tasks/scanners/base_scanner.rb +22 -14
- data/lib/i18n/tasks/scanners/pattern_scanner.rb +2 -1
- data/lib/i18n/tasks/unused_keys.rb +13 -13
- data/lib/i18n/tasks/used_keys.rb +39 -38
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/i18n_tasks_spec.rb +41 -40
- data/spec/locale_tree/siblings_spec.rb +26 -1
- data/spec/support/i18n_tasks_output_matcher.rb +4 -1
- data/spec/support/trees.rb +6 -1
- data/spec/used_keys_spec.rb +23 -15
- metadata +4 -11
- data/lib/i18n/tasks/file_structure.rb +0 -19
- data/lib/i18n/tasks/key.rb +0 -48
- data/lib/i18n/tasks/key/key_group.rb +0 -45
- data/lib/i18n/tasks/key/match_pattern.rb +0 -24
- data/lib/i18n/tasks/key/usages.rb +0 -12
- data/lib/i18n/tasks/key_group.rb +0 -68
- data/spec/key_group_spec.rb +0 -49
@@ -1,45 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module I18n
|
3
|
-
module Tasks
|
4
|
-
class Key
|
5
|
-
module KeyGroup
|
6
|
-
attr_accessor :key_group
|
7
|
-
|
8
|
-
def self.included(base)
|
9
|
-
base.class_eval do
|
10
|
-
extend ClassMethods
|
11
|
-
delegate_to_attr :[], :key?
|
12
|
-
delegate_to_attr_accessor :type, :locale
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def attr
|
17
|
-
key_group.attr.merge @own_attr
|
18
|
-
end
|
19
|
-
|
20
|
-
def clone_orphan
|
21
|
-
clone.tap { |k| k.key_group = nil }
|
22
|
-
end
|
23
|
-
|
24
|
-
module ClassMethods
|
25
|
-
def delegate_to_attr_accessor(*methods)
|
26
|
-
methods.each do |m|
|
27
|
-
define_method(m) do
|
28
|
-
@own_attr[m] || (kg = key_group) && kg.attr[m]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def delegate_to_attr(*methods)
|
34
|
-
methods.each do |m|
|
35
|
-
define_method(m) do |*args|
|
36
|
-
@own_attr.send(m, *args) ||
|
37
|
-
(kg = key_group) && kg.attr.send(m, *args)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module I18n
|
3
|
-
module Tasks
|
4
|
-
class Key
|
5
|
-
module MatchPattern
|
6
|
-
def key_match_pattern
|
7
|
-
@key_match_pattern ||= begin
|
8
|
-
k = key
|
9
|
-
"#{k.gsub(/\#{.*?}/, '*')}#{'*' if k.end_with?('.')}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# A key interpolated with expression
|
14
|
-
def expr?
|
15
|
-
if @is_expr.nil?
|
16
|
-
k = key
|
17
|
-
@is_expr = (k =~ /\#{.*?}/ || k.end_with?('.'))
|
18
|
-
end
|
19
|
-
@is_expr
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/i18n/tasks/key_group.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'set'
|
3
|
-
module I18n
|
4
|
-
module Tasks
|
5
|
-
# Container for keys with shared attributes
|
6
|
-
class KeyGroup
|
7
|
-
attr_reader :keys, :attr, :key_names
|
8
|
-
|
9
|
-
delegate :size, :length, :each, :[], :blank?, to: :keys
|
10
|
-
include Enumerable
|
11
|
-
|
12
|
-
def initialize(keys, attr = {})
|
13
|
-
@keys = if keys && !keys[0].is_a?(::I18n::Tasks::Key)
|
14
|
-
keys.map { |key| I18n::Tasks::Key.new(key) }
|
15
|
-
else
|
16
|
-
keys
|
17
|
-
end
|
18
|
-
@keys.each { |key| key.key_group ||= self } unless attr.delete(:orphan)
|
19
|
-
|
20
|
-
@keys_by_name = @keys.inject({}) { |h, k| h[k.key.to_s] = k; h }
|
21
|
-
@key_names = @keys.map(&:key)
|
22
|
-
@attr = attr
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_by_name(key)
|
26
|
-
@keys_by_name[key.to_s]
|
27
|
-
end
|
28
|
-
|
29
|
-
def key_names_set
|
30
|
-
@key_names_set ||= Set.new(@key_names)
|
31
|
-
end
|
32
|
-
|
33
|
-
def include?(key)
|
34
|
-
key_names_set.include?(key.to_s)
|
35
|
-
end
|
36
|
-
|
37
|
-
def sort!(&block)
|
38
|
-
@keys.sort!(&block)
|
39
|
-
@key_names = @keys.map(&:to_s)
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
# Sort keys by their attributes in order
|
44
|
-
# @param [Hash] order e.g. {locale: :asc, type: :desc, key: :asc}
|
45
|
-
def sort_by_attr!(order)
|
46
|
-
order_keys = order.keys
|
47
|
-
sort! { |a, b|
|
48
|
-
by = order_keys.detect { |by| a[by] != b[by] }
|
49
|
-
order[by] == :desc ? b[by] <=> a[by] : a[by] <=> b[by]
|
50
|
-
}
|
51
|
-
self
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_a
|
55
|
-
@array ||= keys.map(&:attr)
|
56
|
-
end
|
57
|
-
|
58
|
-
alias as_json to_a
|
59
|
-
|
60
|
-
def merge(other)
|
61
|
-
KeyGroup.new(keys + other.keys,
|
62
|
-
type: [attr[:type], other.attr[:type]].flatten.compact)
|
63
|
-
end
|
64
|
-
|
65
|
-
alias + merge
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/spec/key_group_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'KeyGroup' do
|
5
|
-
def key_group(group, attr = {})
|
6
|
-
::I18n::Tasks::KeyGroup.new(group, attr)
|
7
|
-
end
|
8
|
-
|
9
|
-
let!(:kg_attr) { { a: :b, x: '0' } }
|
10
|
-
let!(:kg) { key_group %w(a b), kg_attr }
|
11
|
-
|
12
|
-
it('#attr') { expect(kg.attr).to eq kg_attr }
|
13
|
-
|
14
|
-
it '#to_a' do
|
15
|
-
expect(kg.to_a).to eq [
|
16
|
-
{key: 'a'}.merge(kg_attr),
|
17
|
-
{key: 'b'}.merge(kg_attr)
|
18
|
-
]
|
19
|
-
end
|
20
|
-
|
21
|
-
it '#merge' do
|
22
|
-
kg2_attr = {a: :b, x: '1', c: :d}
|
23
|
-
kg2 = key_group %w(c), kg2_attr
|
24
|
-
kg3 = key_group [{key: 'd', prop: true}]
|
25
|
-
expect([kg, kg2, kg3].reduce(:+).to_a).to eq [
|
26
|
-
{key: 'a'}.merge(kg_attr),
|
27
|
-
{key: 'b'}.merge(kg_attr),
|
28
|
-
{key: 'c'}.merge(kg2_attr),
|
29
|
-
{key: 'd', prop: true}
|
30
|
-
]
|
31
|
-
end
|
32
|
-
|
33
|
-
it '#merge shared attr' do
|
34
|
-
kg2 = key_group %w(c d), kg_attr
|
35
|
-
expect((kg + kg2).keys[0].own_attr).to eq kg.keys[0].own_attr
|
36
|
-
end
|
37
|
-
|
38
|
-
it '#sort!' do
|
39
|
-
kg = key_group [{key: 'a', prop: '0'}, {key: 'b', prop: '1'}]
|
40
|
-
kg.sort! { |a, b| b[:prop] <=> a[:prop] }
|
41
|
-
expect(kg.keys[0][:prop]).to eq '1'
|
42
|
-
end
|
43
|
-
|
44
|
-
it '#sort_by_attr!' do
|
45
|
-
expect(key_group(%w(a b c)).tap { |kg|
|
46
|
-
kg.sort_by_attr!(key: :desc)
|
47
|
-
}.keys.map(&:key)).to eq %w(c b a)
|
48
|
-
end
|
49
|
-
end
|