aigu 0.5 → 0.5.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: 2541e277f5d4bb08688838d37d097f32567a2682
4
- data.tar.gz: af50d9f37a958dfd01306b5206434334d3feb46a
3
+ metadata.gz: 5fdb5bb14cd6a7eae3740682157c4b191a4cec7e
4
+ data.tar.gz: 12e0582f9321bae273c470f63d753cf5b4454ef5
5
5
  SHA512:
6
- metadata.gz: 2bd8d227116755e4eeecacfd2cd91558cfa7c13881804acfa261cd0ec66454902e71d1fd1bf4ac093749be64c4a50e27888323802d2ea18100e39c758c6aaa45
7
- data.tar.gz: 3ecec7944c56ef8c42180db1033ed45489840610b5a27589fbe17d5a5cd77f6fc2b19129bcb50c62e998873cfcdd2c206cd856cfef0d1cdd902407031c09186e
6
+ metadata.gz: e6c9afb797fdd833f2ae97f922fe2a428b4187f6ebfd63ceae744bc5f3d0ba6dd26603f2fc7c7bd56596a3eaf273bfbaeab676299d7d5eddb8bbb5917dd58834
7
+ data.tar.gz: a44afd273329859bd8896affb29ac95560470dcc7a2c9c530bb5489d795b6cd82a885ad6da7df6d501e95ee0a9141a5c298c8dc87d63a27f198fbeb0a48c4a8b
data/README.md CHANGED
@@ -44,13 +44,13 @@ $ aigu <export-command> --locale=fr --input-directory=config/locales --output-fi
44
44
  | `output-file` | The path to the JSON file that will be written by `aigu` |
45
45
  | `ignore` | The patterns `aigu` will use to skip ignored files (eg. `routes.yml`) |
46
46
 
47
- | Command | File format |
48
- |-------------------|-------------------------------------------------------|
49
- | `rails-export` | Rails YAML |
50
- | `android-export` | Android XML |
51
- | `core-export` | Java Enum Core |
52
- | `ios-export` | iOS strings & stringsdict |
53
- | `ember-export` | Ember.js JavaScript (`node` and `babel` are required) |
47
+ | Command | File format |
48
+ |-------------------|----------------------------|
49
+ | `rails-export` | Rails YAML |
50
+ | `android-export` | Android XML |
51
+ | `core-export` | Java Enum Core |
52
+ | `ios-export` | iOS strings & stringsdict |
53
+ | `ember-export` | Ember.js JavaScript |
54
54
 
55
55
  ### Importing the JSON file from Accent
56
56
 
@@ -14,28 +14,15 @@ module Aigu
14
14
  else
15
15
  puts "Processing #{filepath}"
16
16
 
17
- content = JSON.parse(run_javascript_script(file))
18
-
17
+ content = File.read(file).gsub(/^export default (.*);$/m, '\1')
18
+ content = JSON.parse(content)
19
19
  content = flattenize_hash(content)
20
+
20
21
  @output.merge! content
21
22
  end
22
23
  end
23
24
  end
24
25
 
25
- def run_javascript_script(file)
26
- script = "require('babel/register')({stage: 0}); console.log(JSON.stringify(require('#{file}')))"
27
- command = "node -e \"#{script}\" 2>/dev/null"
28
- puts "Executing `#{command}`"
29
- content = `#{command}`
30
-
31
- if content.empty?
32
- puts 'There was an error when executing the command. Please make sure `node` and `babel` are installed.'
33
- exit 0
34
- end
35
-
36
- content
37
- end
38
-
39
26
  def write_json_file
40
27
  file_path = @output_file
41
28
  puts "Generating #{file_path}"
@@ -37,15 +37,20 @@ module Aigu
37
37
 
38
38
  @object.each_pair do |key, value|
39
39
  parts = key.split('.')
40
- hash = @blob[parts.first]
41
40
 
42
- parts.each_with_index do |part, index|
43
- next if index.zero?
41
+ if parts.length == 1
42
+ @blob[parts.first] = value
43
+ else
44
+ hash = @blob[parts.first]
44
45
 
45
- if index + 1 < parts.length
46
- hash = hash[part]
47
- else
48
- hash[part] = value
46
+ parts.each_with_index do |part, index|
47
+ next if index.zero?
48
+
49
+ if index + 1 < parts.length
50
+ hash = hash[part]
51
+ else
52
+ hash[part] = value
53
+ end
49
54
  end
50
55
  end
51
56
  end
@@ -1,3 +1,3 @@
1
1
  module Aigu
2
- VERSION = '0.5'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aigu::EmberExporter do
4
+ describe :flattenize_hash do
5
+ let(:exporter) { Aigu::EmberExporter.new }
6
+
7
+ let(:flattenized_content) { exporter.send(:flattenize_hash, content) }
8
+
9
+ let(:content) do
10
+ {
11
+ 'foo' => {
12
+ 'bar' => 'Bar',
13
+ 'baz' => 'Baz',
14
+ 'nested' => {
15
+ 'one' => 'One',
16
+ 'two' => 'Two'
17
+ }
18
+ },
19
+ 'three' => 'Three'
20
+ }
21
+ end
22
+
23
+ let(:expected_content) do
24
+ {
25
+ 'foo.bar' => 'Bar',
26
+ 'foo.baz' => 'Baz',
27
+ 'foo.nested.one' => 'One',
28
+ 'foo.nested.two' => 'Two',
29
+ 'three' => 'Three'
30
+ }
31
+ end
32
+
33
+ it { expect(flattenized_content).to eql expected_content }
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aigu::EmberImporter do
4
+ describe :build_blob do
5
+ let(:importer) { Aigu::EmberImporter.new }
6
+
7
+ before do
8
+ importer.instance_variable_set(:@object, object)
9
+ importer.send(:build_blob)
10
+ end
11
+
12
+ let(:blob) { importer.instance_variable_get(:@blob) }
13
+
14
+ let(:object) do
15
+ {
16
+ 'foo.bar' => 'Bar',
17
+ 'foo.baz' => 'Baz',
18
+ 'foo.nested.one' => 'One',
19
+ 'foo.nested.two' => 'Two',
20
+ 'three' => 'Three'
21
+ }
22
+ end
23
+
24
+ let(:expected_blob) do
25
+ {
26
+ 'foo' => {
27
+ 'bar' => 'Bar',
28
+ 'baz' => 'Baz',
29
+ 'nested' => {
30
+ 'one' => 'One',
31
+ 'two' => 'Two'
32
+ }
33
+ },
34
+ 'three' => 'Three'
35
+ }
36
+ end
37
+
38
+ it { expect(blob).to eql expected_blob }
39
+ end
40
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aigu
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-23 00:00:00.000000000 Z
12
+ date: 2015-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -141,6 +141,8 @@ files:
141
141
  - spec/aigu/android_importer_spec.rb
142
142
  - spec/aigu/core_exporter_spec.rb
143
143
  - spec/aigu/core_importer_spec.rb
144
+ - spec/aigu/ember_exporter_spec.rb
145
+ - spec/aigu/ember_importer_spec.rb
144
146
  - spec/aigu/ios_exporter_spec.rb
145
147
  - spec/aigu/ios_importer_spec.rb
146
148
  - spec/aigu/rails_exporter_spec.rb
@@ -176,6 +178,8 @@ test_files:
176
178
  - spec/aigu/android_importer_spec.rb
177
179
  - spec/aigu/core_exporter_spec.rb
178
180
  - spec/aigu/core_importer_spec.rb
181
+ - spec/aigu/ember_exporter_spec.rb
182
+ - spec/aigu/ember_importer_spec.rb
179
183
  - spec/aigu/ios_exporter_spec.rb
180
184
  - spec/aigu/ios_importer_spec.rb
181
185
  - spec/aigu/rails_exporter_spec.rb