i18n-tasks 0.4.1 → 0.4.2
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 +2 -1
- data/CHANGES.md +4 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/i18n/tasks/commands.rb +2 -1
- data/lib/i18n/tasks/configuration.rb +10 -2
- data/lib/i18n/tasks/data/tree/node.rb +12 -9
- data/lib/i18n/tasks/data/tree/nodes.rb +4 -2
- data/lib/i18n/tasks/data/tree/siblings.rb +8 -5
- data/lib/i18n/tasks/data/tree/traversal.rb +4 -2
- data/lib/i18n/tasks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c36031ff1ffa5b67ffd68c4fc5375f4508598eff
|
4
|
+
data.tar.gz: 1dec92e192b4f30d33ba4411a69c55cb09ff542e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636e7c94c6890519aa730e7b1aa13a8dba0c9d323c0b59214dc9474bf39fff80266267a770e41974eff888f7805fc59be63c1d3873094558d23319a13f1eb344
|
7
|
+
data.tar.gz: ce2e60ac8f14d31357a9508a9160f7cd2eb308e3c5df0793156b22fbcd160356188a40eb3a7d215f2894c23893510e6068dcb8461f60159654e0fdc2afaeba1e
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ i18n-tasks can be used with any project using [i18n][i18n-gem] (default in Rails
|
|
18
18
|
Add to Gemfile:
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem 'i18n-tasks', '~> 0.4.
|
21
|
+
gem 'i18n-tasks', '~> 0.4.2'
|
22
22
|
```
|
23
23
|
|
24
24
|
i18n-tasks does not load or execute any of the application's code but performs static-only analysic.
|
data/lib/i18n/tasks/commands.rb
CHANGED
@@ -98,7 +98,8 @@ module I18n::Tasks
|
|
98
98
|
cmd :config do
|
99
99
|
cfg = i18n_task.config_for_inspect.to_yaml
|
100
100
|
cfg.sub! /\A---\n/, ''
|
101
|
-
cfg.gsub! /^([^\s-]
|
101
|
+
cfg.gsub! /^([^\s-].+?:)/, Term::ANSIColor.cyan(Term::ANSIColor.bold('\1'))
|
102
|
+
cfg.gsub! '!ruby/hash:ActiveSupport::HashWithIndifferentAccess', ''
|
102
103
|
puts cfg
|
103
104
|
end
|
104
105
|
|
@@ -9,6 +9,7 @@ module I18n::Tasks::Configuration
|
|
9
9
|
config/i18n-tasks.yml config/i18n-tasks.yml.erb
|
10
10
|
i18n-tasks.yml i18n-tasks.yml.erb
|
11
11
|
)
|
12
|
+
|
12
13
|
def file_config
|
13
14
|
file = CONFIG_FILES.detect { |f| File.exists?(f) }
|
14
15
|
file = YAML.load(Erubis::Eruby.new(File.read(file)).result) if file
|
@@ -27,7 +28,7 @@ module I18n::Tasks::Configuration
|
|
27
28
|
@config_sections[:data] ||= begin
|
28
29
|
{
|
29
30
|
adapter: data.class.name,
|
30
|
-
config:
|
31
|
+
config: data.config
|
31
32
|
}
|
32
33
|
end
|
33
34
|
end
|
@@ -97,6 +98,13 @@ module I18n::Tasks::Configuration
|
|
97
98
|
|
98
99
|
def config_for_inspect
|
99
100
|
# hide empty sections, stringify keys
|
100
|
-
Hash[config_sections.reject { |k, v| v.empty? }.map { |k, v|
|
101
|
+
Hash[config_sections.reject { |k, v| v.empty? }.map { |k, v|
|
102
|
+
[k.to_s, v.respond_to?(:stringify_keys) ? v.stringify_keys : v] }].tap do |h|
|
103
|
+
h.each do |_k, v|
|
104
|
+
if v.is_a?(Hash) && v.key?('config')
|
105
|
+
v.merge! v.delete('config')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
101
109
|
end
|
102
110
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'i18n/tasks/data/tree/traversal'
|
2
4
|
require 'i18n/tasks/data/tree/siblings'
|
3
5
|
module I18n::Tasks::Data::Tree
|
@@ -5,12 +7,12 @@ module I18n::Tasks::Data::Tree
|
|
5
7
|
attr_accessor :value
|
6
8
|
attr_reader :key, :children, :parent
|
7
9
|
|
8
|
-
def initialize(
|
9
|
-
@key = key.try(:to_s)
|
10
|
-
@value = value
|
11
|
-
@data = data
|
12
|
-
@parent = parent
|
13
|
-
self.children = children if children
|
10
|
+
def initialize(opts = {})
|
11
|
+
@key = opts[:key].try(:to_s)
|
12
|
+
@value = opts[:value]
|
13
|
+
@data = opts[:data]
|
14
|
+
@parent = opts[:parent]
|
15
|
+
self.children = opts[:children] if opts[:children]
|
14
16
|
end
|
15
17
|
|
16
18
|
def attributes
|
@@ -113,7 +115,8 @@ module I18n::Tasks::Data::Tree
|
|
113
115
|
derive.append!(nodes)
|
114
116
|
end
|
115
117
|
|
116
|
-
def full_key(
|
118
|
+
def full_key(opts = {})
|
119
|
+
root = opts.key?(:root) ? opts[:root] : true
|
117
120
|
@full_key ||= {}
|
118
121
|
@full_key[root] ||= "#{"#{parent.full_key(root: root)}." if parent? && (root || parent.parent?)}#{key}"
|
119
122
|
end
|
@@ -151,7 +154,7 @@ module I18n::Tasks::Data::Tree
|
|
151
154
|
delegate :to_json, to: :to_hash
|
152
155
|
delegate :to_yaml, to: :to_hash
|
153
156
|
|
154
|
-
def inspect(level
|
157
|
+
def inspect(level = 0)
|
155
158
|
label =
|
156
159
|
if null?
|
157
160
|
Term::ANSIColor.dark '∅'
|
@@ -167,7 +170,7 @@ module I18n::Tasks::Data::Tree
|
|
167
170
|
|
168
171
|
r = "#{' ' * level}#{label}"
|
169
172
|
if children?
|
170
|
-
r += "\n" + children.map { |c| c.inspect(level
|
173
|
+
r += "\n" + children.map { |c| c.inspect(level + 1) }.join("\n") if children?
|
171
174
|
end
|
172
175
|
r
|
173
176
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'i18n/tasks/data/tree/traversal'
|
2
4
|
module I18n::Tasks::Data::Tree
|
3
5
|
# A list of nodes
|
4
6
|
class Nodes
|
5
7
|
attr_reader :list
|
6
8
|
|
7
|
-
def initialize(
|
8
|
-
@list = nodes.to_a.clone
|
9
|
+
def initialize(opts = {})
|
10
|
+
@list = opts[:nodes] ? opts[:nodes].to_a.clone : []
|
9
11
|
end
|
10
12
|
|
11
13
|
delegate :each, :present?, :empty?, :blank?, :size, :to_a, to: :@list
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'i18n/tasks/data/tree/traversal'
|
2
4
|
require 'i18n/tasks/data/tree/nodes'
|
3
5
|
module I18n::Tasks::Data::Tree
|
@@ -7,11 +9,11 @@ module I18n::Tasks::Data::Tree
|
|
7
9
|
class Siblings < Nodes
|
8
10
|
attr_reader :parent, :key_to_node
|
9
11
|
|
10
|
-
def initialize(
|
11
|
-
super(nodes: nodes)
|
12
|
+
def initialize(opts = {})
|
13
|
+
super(nodes: opts[:nodes])
|
12
14
|
@key_to_node = siblings.inject({}) { |h, node| h[node.key] = node; h }
|
13
15
|
@parent = first.try(:parent) || Node.null
|
14
|
-
self.parent = parent if parent
|
16
|
+
self.parent = opts[:parent] if opts[:parent]
|
15
17
|
end
|
16
18
|
|
17
19
|
def attributes
|
@@ -111,9 +113,10 @@ module I18n::Tasks::Data::Tree
|
|
111
113
|
|
112
114
|
# build forest from nested hash, e.g. {'es' => { 'common' => { name => 'Nombre', 'age' => 'Edad' } } }
|
113
115
|
# this is the native i18n gem format
|
114
|
-
def from_nested_hash(hash,
|
116
|
+
def from_nested_hash(hash, opts = {})
|
117
|
+
opts[:parent] ||= Node.null
|
115
118
|
Siblings.new nodes: hash.map { |key, value| Node.from_key_value key, value },
|
116
|
-
parent: parent
|
119
|
+
parent: opts[:parent]
|
117
120
|
end
|
118
121
|
|
119
122
|
alias [] from_nested_hash
|
@@ -14,7 +14,8 @@ module I18n::Tasks::Data::Tree
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# @param root include root in full key
|
17
|
-
def keys(
|
17
|
+
def keys(opts = {}, &visitor)
|
18
|
+
root = opts.key?(:root) ? opts[:root] : true
|
18
19
|
return to_enum(:keys, root: root) unless visitor
|
19
20
|
leaves { |node| visitor.yield(node.full_key(root: root), node) }
|
20
21
|
end
|
@@ -65,7 +66,8 @@ module I18n::Tasks::Data::Tree
|
|
65
66
|
end
|
66
67
|
|
67
68
|
# @return Siblings
|
68
|
-
def select_keys(
|
69
|
+
def select_keys(opts = {}, &block)
|
70
|
+
root = opts.key?(:root) ? opts[:root] : true
|
69
71
|
ok = {}
|
70
72
|
keys(root: root) do |full_key, node|
|
71
73
|
if block.yield(full_key, node)
|
data/lib/i18n/tasks/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|