aigu 0.2.1 → 0.3

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: 576a5075e0e5ce42d8972fc3ad0cf8f4e914eb3c
4
- data.tar.gz: 39f8f36e2c59d8b19e901f5ed680157aa9060c68
3
+ metadata.gz: f34d9e639e54249277066684afa8210846b03c2a
4
+ data.tar.gz: b43f7b175e500d47cd191376e119045800017bab
5
5
  SHA512:
6
- metadata.gz: c1ced7aaa5b3d8a7498c8a1b0fe7c87e2a1e5dc90d462ca579b85d4b1e79b31cadbba6fb380d86d90faa908d5dfca3bb8a4c79286c321422645bc17265fa9f8a
7
- data.tar.gz: 1154f12f06b73c1c5f2fdc0313ac54ff6c375f9e21a9e420639a9fc484a120aca73d897f2ba115f7ff4e6507f8deebf5706829542784d51ff4b66c38af9237c6
6
+ metadata.gz: 1a572a3c4e084f373cf129d51ba89993b3e593a5acc604142180f0e861c44dd9069400b8e9fd3c7799016af2e8eea3e5a46fc7b3bbc2efee0a0d460b1003426d
7
+ data.tar.gz: 5716103f5a1a65685b52e54e6aa780c1a472ea605fc2df0032a200b08c8cb26bb0becf6261ae1d9c219fd94ee6c47d17ed89b7c52a0630aac8bfa15512a3e0e6
data/README.md CHANGED
@@ -27,13 +27,14 @@ file. This file will then be compatible with Accent.
27
27
  $ aigu export --locale=fr --input-directory=config/locales --output-file=my-project.json
28
28
  ```
29
29
 
30
- ### Options
30
+ #### Options
31
31
 
32
32
  | Option | Description |
33
33
  |-------------------|---------------------------------------------------------------------------------------------------------------------------|
34
34
  | `locale` | The locale used to find localization files. Files that match `*.<locale>.yml` in the input directory will be processed. |
35
35
  | `input-directory` | The directory used to find localization files |
36
36
  | `output-file` | The path to the JSON file that will be written by `aigu` |
37
+ | `ignore` | The patterns `aigu` will use to skip ignored files (eg. `routes.yml`)
37
38
 
38
39
  ### Importing the JSON file from Accent
39
40
 
@@ -44,7 +45,7 @@ the original YAML file structure.
44
45
  $ aigu import --locale=fr --input-file=file-from-accent.json --output-directory=config/locales
45
46
  ```
46
47
 
47
- ### Options
48
+ #### Options
48
49
 
49
50
  | Option | Description |
50
51
  |--------------------|---------------------------------------------------------------------------------------------------|
@@ -52,6 +53,20 @@ $ aigu import --locale=fr --input-file=file-from-accent.json --output-directory=
52
53
  | `input-file` | The path to the Accent-generated JSON file |
53
54
  | `output-directory` | The directory where the localization YAML files will be generated |
54
55
 
56
+ ### Using `aigu.yml`
57
+
58
+ Instead of using command-line arguments when running the `aigu` command, you
59
+ can create a `aigu.yml` file at the root of your project and hard-code options
60
+ in that file.
61
+
62
+ ```yaml
63
+ ignore:
64
+ - routes.yml
65
+ - rails/**/*.yml
66
+ output-directory: config/locales
67
+ input-directory: config/locales
68
+ ```
69
+
55
70
  ## License
56
71
 
57
72
  `Aigu` is © 2014 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/aigu/blob/master/LICENSE.md) file.
data/Rakefile CHANGED
@@ -1,4 +1,14 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: :spec
7
+
8
+ desc 'Run all specs'
9
+ RSpec::Core::RakeTask.new(:spec) do |task|
10
+ task.pattern = 'spec/**/*_spec.rb'
11
+ end
2
12
 
3
13
  desc 'Start an IRB session with the gem'
4
14
  task :console do
@@ -4,7 +4,9 @@ module Aigu
4
4
  @env = env
5
5
  @command = argv.first =~ /^[^-]/ ? argv.shift : nil
6
6
  @argv = argv
7
- parse_options
7
+ @options = {}
8
+ @options = parse_options_from_yaml(@options)
9
+ @options = parse_options_from_arguments(@options)
8
10
  end
9
11
 
10
12
  def run
@@ -21,30 +23,53 @@ module Aigu
21
23
  service_object.process!
22
24
  end
23
25
 
24
- def parse_options
25
- @options = {}
26
+ protected
27
+
28
+ def parse_options_from_yaml(options)
29
+ file = File.join(Dir.pwd, '.aigu.yml')
30
+
31
+ if File.exists?(file)
32
+ # Load YAML content
33
+ content = YAML.load_file(file)
26
34
 
35
+ # Symbolize keys
36
+ content = content.reduce({}) do |memo, (key, value)|
37
+ memo.merge! key.to_sym => value
38
+ end
39
+
40
+ # Merge with existing options
41
+ options = options.merge(content)
42
+ end
43
+
44
+ options
45
+ end
46
+
47
+ def parse_options_from_arguments(options)
27
48
  OptionParser.new do |opts|
28
49
  opts.banner = 'Usage: aigu [options]'
29
50
 
30
51
  opts.on('--input-directory=', 'The directory in which the Rails YAML localization files are stored.') do |directory|
31
- @options[:input_directory] = directory
52
+ options[:input_directory] = directory
32
53
  end
33
54
 
34
55
  opts.on('--output-directory=', 'The directory in which the Rails YAML localization files will be generated.') do |directory|
35
- @options[:output_directory] = directory
56
+ options[:output_directory] = directory
36
57
  end
37
58
 
38
59
  opts.on('--input-file=', 'The JSON file generated by Accent.') do |file|
39
- @options[:input_file] = file
60
+ options[:input_file] = file
40
61
  end
41
62
 
42
63
  opts.on('--output-file=', 'The JSON file that will be generated for Accent.') do |file|
43
- @options[:output_file] = file
64
+ options[:output_file] = file
44
65
  end
45
66
 
46
67
  opts.on('--locale=', 'The locale to use. Files will be processed/generated using the "<file>.<locale>.yml" pattern.') do |locale|
47
- @options[:locale] = locale
68
+ options[:locale] = locale
69
+ end
70
+
71
+ opts.on('--ignore=', 'Patterns to ignore, separated by commas') do |ignore|
72
+ options[:ignore] = ignore.split(',')
48
73
  end
49
74
 
50
75
  opts.on_tail('-h', '--help', 'Show this message') do
@@ -53,6 +78,8 @@ module Aigu
53
78
  end
54
79
 
55
80
  end.parse! @argv
81
+
82
+ options
56
83
  end
57
84
  end
58
85
  end
@@ -1,13 +1,20 @@
1
1
  module Aigu
2
2
  class Exporter
3
- def initialize(output_file: nil, input_directory: nil, locale: nil)
4
- @output_file = output_file
5
- @input_directory = input_directory
6
- @locale = locale
3
+ def initialize(opts = {})
4
+ @output_file = opts[:output_file]
5
+ @input_directory = opts[:input_directory]
6
+ @locale = opts[:locale]
7
+ @ignore = opts[:ignore]
7
8
  end
8
9
 
9
10
  def process!
10
11
  puts "Generating Accent JSON file `#{@output_file}` based on YAML localization files in `#{@input_directory}` directory"
12
+
13
+ if @ignore
14
+ print 'Ignoring '
15
+ puts @ignore.join(', ')
16
+ end
17
+
11
18
  puts '---'
12
19
 
13
20
  build_output
@@ -22,14 +29,22 @@ module Aigu
22
29
  def build_output
23
30
  @output = {}
24
31
 
25
- Dir[File.join(@input_directory, '**', "*.#{@locale}.yml")].each do |file|
26
- content = YAML.load_file(file)
27
- base_key = file.gsub(@input_directory, '').gsub(/^\/*/, '').gsub(/\.yml$/, '|')
32
+ pattern = File.join(@input_directory, '**', "*.#{@locale}.yml")
33
+ Dir[pattern].each do |file|
34
+ filepath = file.gsub(/\A#{@input_directory}\//, '')
35
+
36
+ if ignored_filepath?(filepath)
37
+ puts "Ignoring #{filepath}"
38
+ else
39
+ puts "Processing #{filepath}"
40
+ content = YAML.load_file(file)
41
+ base_key = file.gsub(@input_directory, '').gsub(/^\/*/, '').gsub(/\.yml$/, '|')
28
42
 
29
- content = flattenize_hash(content, base_key)
30
- content = flattenize_content_values(content)
31
- content = globalize_content_keys(content)
32
- @output.merge! content
43
+ content = flattenize_hash(content, base_key)
44
+ content = flattenize_content_values(content)
45
+ content = globalize_content_keys(content)
46
+ @output.merge! content
47
+ end
33
48
  end
34
49
  end
35
50
 
@@ -90,5 +105,11 @@ module Aigu
90
105
  { base_key => hash }
91
106
  end
92
107
  end
108
+
109
+ def ignored_filepath?(filepath)
110
+ @ignore && @ignore.any? do |pattern|
111
+ File.fnmatch(pattern, filepath, File::FNM_PATHNAME | File::FNM_DOTMATCH)
112
+ end
113
+ end
93
114
  end
94
115
  end
@@ -2,10 +2,10 @@ module Aigu
2
2
  class Importer
3
3
  ARRAY_REGEX = /___KEY___(?<index>\d+)$/
4
4
 
5
- def initialize(input_file: nil, output_directory: nil, locale: nil)
6
- @input_file = input_file
7
- @output_directory = output_directory
8
- @locale = locale
5
+ def initialize(opts = {})
6
+ @input_file = opts[:input_file]
7
+ @output_directory = opts[:output_directory]
8
+ @locale = opts[:locale]
9
9
  end
10
10
 
11
11
  def process!
@@ -1,3 +1,3 @@
1
1
  module Aigu
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3'
3
3
  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.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost