i18n_flow 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/i18n_flow/version.rb +1 -1
- data/lib/i18n_flow/yaml_ast_proxy/mapping.rb +10 -1
- data/spec/lib/i18n_flow/formatter_spec.rb +31 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a3c18156e0fdfebf2f9b9de3f6965eb86e17d2
|
4
|
+
data.tar.gz: 807640fefba2f86593ae49ec5d1abe385592eafc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7953b9c89839512ca1fa0b07d4e67f58a6d2bc15fe9865640fc21c84c2bdadf2d851f94dfdffbe510166ac9aea40702b3b59044909e90e742b7017a775bef5a7
|
7
|
+
data.tar.gz: f853af82979315aafbcb43d7c5128289ec6e1da90992b6fac1132f1dc2c1497cdd9ba278bb142c44b15fe0925b68c8f79140f8416f91dbcaaf0fffd7f95654f3
|
data/Gemfile.lock
CHANGED
data/lib/i18n_flow/version.rb
CHANGED
@@ -57,7 +57,7 @@ module I18nFlow::YamlAstProxy
|
|
57
57
|
|
58
58
|
def sort_keys!
|
59
59
|
@indexed_object = indexed_object
|
60
|
-
.sort_by { |k, v| [v
|
60
|
+
.sort_by { |k, v| [sort_order(v), k] }
|
61
61
|
.to_h
|
62
62
|
@cache = nil
|
63
63
|
synchronize!
|
@@ -82,5 +82,14 @@ module I18nFlow::YamlAstProxy
|
|
82
82
|
children = indexed_object.flat_map { |k, v| [Psych::Nodes::Scalar.new(k), v] }
|
83
83
|
node.children.replace(children)
|
84
84
|
end
|
85
|
+
|
86
|
+
def sort_order(node)
|
87
|
+
case node
|
88
|
+
when Psych::Nodes::Alias then -1
|
89
|
+
when Psych::Nodes::Scalar then node.anchor ? 1 : 0
|
90
|
+
when Psych::Nodes::Mapping then node.anchor ? 1 : 2
|
91
|
+
else 0
|
92
|
+
end
|
93
|
+
end
|
85
94
|
end
|
86
95
|
end
|
@@ -95,7 +95,7 @@ describe I18nFlow::Formatter do
|
|
95
95
|
expect(formatted.to_yaml).to eq(result.to_yaml)
|
96
96
|
end
|
97
97
|
|
98
|
-
it 'should move mappings
|
98
|
+
it 'should move mappings to the bottom' do
|
99
99
|
ast = parse_yaml(<<-YAML)
|
100
100
|
en:
|
101
101
|
alfa: 'A'
|
@@ -132,6 +132,36 @@ describe I18nFlow::Formatter do
|
|
132
132
|
formatted = format_ast(ast)
|
133
133
|
expect(formatted.to_yaml).to eq(result.to_yaml)
|
134
134
|
end
|
135
|
+
|
136
|
+
it 'should move anchors before the mappings' do
|
137
|
+
ast = parse_yaml(<<-YAML)
|
138
|
+
en:
|
139
|
+
alfa: 'A'
|
140
|
+
xxx: &xxx
|
141
|
+
echo: 'E'
|
142
|
+
golf: 'G'
|
143
|
+
charlie:
|
144
|
+
<<: *xxx
|
145
|
+
a: 123
|
146
|
+
bravo: 'B'
|
147
|
+
delta: 'D'
|
148
|
+
YAML
|
149
|
+
result = parse_yaml(<<-YAML)
|
150
|
+
en:
|
151
|
+
alfa: 'A'
|
152
|
+
bravo: 'B'
|
153
|
+
delta: 'D'
|
154
|
+
xxx: &xxx
|
155
|
+
echo: 'E'
|
156
|
+
golf: 'G'
|
157
|
+
charlie:
|
158
|
+
<<: *xxx
|
159
|
+
a: 123
|
160
|
+
YAML
|
161
|
+
|
162
|
+
formatted = format_ast(ast)
|
163
|
+
expect(formatted.to_yaml).to eq(result.to_yaml)
|
164
|
+
end
|
135
165
|
end
|
136
166
|
end
|
137
167
|
end
|