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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '08d2cf8d25372c57651808089a31dedc34a52f81'
4
- data.tar.gz: 2a96774f923502e0dd534c8b632acf4f7e5d232f
3
+ metadata.gz: a7a3c18156e0fdfebf2f9b9de3f6965eb86e17d2
4
+ data.tar.gz: 807640fefba2f86593ae49ec5d1abe385592eafc
5
5
  SHA512:
6
- metadata.gz: '03463815dc69ad05dfb2e4b048201441e212a165947a546f4b8e1828b72f32cda5e1f16ab0d335fe9881bc949cfad7a5fa0eb6acf6ebc50a312cfa5d2080b17b'
7
- data.tar.gz: 4bd655b11d659a008101bd28f113c65d8d03ea59ab7fe969c1c702e2dabacca9b52c20da33f4e2b4c3981f9b74af73cc87dbc11ae96fa269f2bcfd00fdc7f591
6
+ metadata.gz: 7953b9c89839512ca1fa0b07d4e67f58a6d2bc15fe9865640fc21c84c2bdadf2d851f94dfdffbe510166ac9aea40702b3b59044909e90e742b7017a775bef5a7
7
+ data.tar.gz: f853af82979315aafbcb43d7c5128289ec6e1da90992b6fac1132f1dc2c1497cdd9ba278bb142c44b15fe0925b68c8f79140f8416f91dbcaaf0fffd7f95654f3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_flow (0.2.0)
4
+ i18n_flow (0.2.1)
5
5
  psych (>= 3.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  module I18nFlow
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- REVISION = 0
4
+ REVISION = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, REVISION].join('.')
7
7
  end
@@ -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.is_a?(Psych::Nodes::Mapping) ? 1 : 0, k] }
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 at the bottom' do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Iwanaga