i18n_flow 0.2.2 → 0.2.3
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/Gemfile.lock +1 -1
- data/lib/i18n_flow/version.rb +1 -1
- data/lib/i18n_flow/yaml_ast_proxy.rb +4 -0
- data/lib/i18n_flow/yaml_ast_proxy/mapping.rb +10 -1
- data/spec/lib/i18n_flow/formatter_spec.rb +22 -0
- 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: e702abf0558b8dd1ebdd15e1f7823d677b649d6a
|
4
|
+
data.tar.gz: 99d568369b4ed3cd399147147174df3588ffcadd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a786734b4ae407a51ab284cef2f610aa237ce49c3f8e8ff8ae7717b278954e82ebc448d7773b5f51fba7f98cc84816c174a7069ccacf46105a3377d3524948aa
|
7
|
+
data.tar.gz: b1798e0ff0fb80750521f5decbe8db769371518192edb0831b7b627c87831661897d22db36db273b91ac40a6d7a03f44c5821c29b5a7fdcd2a3887b07ee598aa
|
data/Gemfile.lock
CHANGED
data/lib/i18n_flow/version.rb
CHANGED
@@ -79,7 +79,7 @@ module I18nFlow::YamlAstProxy
|
|
79
79
|
def synchronize!
|
80
80
|
return if @locked
|
81
81
|
|
82
|
-
children = indexed_object.flat_map { |k, v| [
|
82
|
+
children = indexed_object.flat_map { |k, v| [key_node(k), v] }
|
83
83
|
node.children.replace(children)
|
84
84
|
end
|
85
85
|
|
@@ -95,5 +95,14 @@ module I18nFlow::YamlAstProxy
|
|
95
95
|
else node.anchor ? -2 : 0
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
def key_node(str)
|
100
|
+
needs_quote = !I18nFlow::YamlAstProxy.scalar_scanner.tokenize(str).is_a?(String)
|
101
|
+
if needs_quote
|
102
|
+
Psych::Nodes::Scalar.new(str, nil, nil, true, true, Psych::Nodes::Scalar::DOUBLE_QUOTED)
|
103
|
+
else
|
104
|
+
Psych::Nodes::Scalar.new(str, nil, nil, true, false, Psych::Nodes::Scalar::PLAIN)
|
105
|
+
end
|
106
|
+
end
|
98
107
|
end
|
99
108
|
end
|
@@ -8,6 +8,28 @@ describe I18nFlow::Formatter do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#format!' do
|
11
|
+
it 'should quote non-string keys' do
|
12
|
+
ast = parse_yaml(<<-YAML)
|
13
|
+
en:
|
14
|
+
1: alpha
|
15
|
+
1.2: bravo
|
16
|
+
foo: chalie
|
17
|
+
true: delta
|
18
|
+
YAML
|
19
|
+
result = parse_yaml(<<-YAML)
|
20
|
+
en:
|
21
|
+
"1": alpha
|
22
|
+
"1.2": bravo
|
23
|
+
foo: chalie
|
24
|
+
"true": delta
|
25
|
+
YAML
|
26
|
+
|
27
|
+
p ast
|
28
|
+
|
29
|
+
formatted = format_ast(ast)
|
30
|
+
expect(formatted.to_yaml).to eq(result.to_yaml)
|
31
|
+
end
|
32
|
+
|
11
33
|
it 'should remove extra whitespaces' do
|
12
34
|
ast = parse_yaml(<<-YAML)
|
13
35
|
en:
|