yaml_locales_jsonizer 0.1.1 → 0.1.2

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: fac54f7386a96d251d72032e0b955d9636cf4d46
4
- data.tar.gz: 1bd37dd320adbb901a31cc00fbea690ade9e7cb9
3
+ metadata.gz: b2b1da4a8908be5e48e2b0bfcd1b9fe0d91ae1e7
4
+ data.tar.gz: 06e5dc0124d4f3dfd3aa7487b55200897114e185
5
5
  SHA512:
6
- metadata.gz: a21001433d2f3c9117f10bd90e7a38647f8714a96114781ff2758637b7150c0811a462b145673503ef6ecb174ab34f6a6665c0daa4f7258242601d621c4c2d2e
7
- data.tar.gz: f5fd9b5125aac8509a758b44cd7429819071b86965b27b7d9d48a8ddf776bcf49d8eff6b55d56650072f3bf1f56670334cc55f0b5f08c02a19daabf3ad609959
6
+ metadata.gz: aaa61776598c5d31a986efe8bed8463525f88cb8e4b6d3601ffa3b85c05fc924bd1f4a49da1d945485b0458b50249e9d3e0dabb4b3f7371e9cc6f45d6bdf9104
7
+ data.tar.gz: 429619921c2d3f990b2ccecd1765f1884fc9aaf615a73c2311573d5d8f945633762b0e873cd127d1c9b8f5882b2bf1fe1c5cf77b908976441e468d54210cab2d
@@ -0,0 +1,2 @@
1
+ rails_load_path = Rails.configuration.i18n[:load_path]
2
+ YamlLocalesJsonizer.load_path ||= rails_load_path || []
@@ -4,7 +4,10 @@ require 'yaml'
4
4
  module YamlLocalesJsonizer
5
5
  end
6
6
 
7
+ require 'yaml_locales_jsonizer/config'
7
8
  require 'yaml_locales_jsonizer/loader'
8
9
  require 'yaml_locales_jsonizer/styles/i18next'
9
10
  require 'yaml_locales_jsonizer/action_view/helper'
10
11
  require 'yaml_locales_jsonizer/engine' if defined?(Rails)
12
+
13
+ YamlLocalesJsonizer.send :extend, YamlLocalesJsonizer::Config
@@ -0,0 +1,33 @@
1
+ module YamlLocalesJsonizer::Config
2
+ attr_accessor :config
3
+
4
+ DEFAULTS = {
5
+ load_path: nil,
6
+ only_files: ['*.yml']
7
+ }
8
+
9
+ def self.extended(mod)
10
+ mod.init_config
11
+ end
12
+
13
+ def init_config
14
+ self.config = DEFAULTS
15
+ end
16
+
17
+ def configure(&block)
18
+ instance_eval(&block)
19
+ config
20
+ end
21
+
22
+ DEFAULTS.keys.each do |method_name|
23
+ define_method method_name do |*vals|
24
+ config[method_name] = vals.first if vals.any?
25
+ config[method_name]
26
+ end
27
+
28
+ define_method "#{method_name}=".to_sym do |val|
29
+ config[method_name] = val
30
+ end
31
+ end
32
+
33
+ end
@@ -17,7 +17,10 @@ module YamlLocalesJsonizer::Loader
17
17
  private
18
18
 
19
19
  def locale_files
20
- %w(en.yml ru.yml).map { |name| Rails.root + "config/locales/#{name}" }
20
+ cfg = YamlLocalesJsonizer
21
+ cfg.load_path.select do |f|
22
+ cfg.only_files.find { |m| File.fnmatch?(m, f) || File.basename(f) == m }
23
+ end
21
24
  end
22
25
 
23
26
  def style
@@ -1,3 +1,3 @@
1
1
  module YamlLocalesJsonizer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -6,8 +6,11 @@ shared_context 'locale files' do
6
6
  end
7
7
 
8
8
  before do
9
- allow(YamlLocalesJsonizer::Loader).to receive(:locale_files)
10
- .and_return(locale_files.keys)
9
+ # add fake data files to load path
10
+ fs = locale_files.keys
11
+ YamlLocalesJsonizer.configure { self.load_path += fs }
12
+
13
+ # and stub YAML to 'load' them
11
14
  allow(YAML).to receive(:load_file) { |file| locale_files[file] }
12
15
  end
13
16
  end
@@ -12,4 +12,18 @@ describe YamlLocalesJsonizer::Loader, '.locales' do
12
12
  ru: { translation: locale_ru }
13
13
  })
14
14
  end
15
+
16
+ context 'with only_files config parameters specified' do
17
+ before do
18
+ YamlLocalesJsonizer.configure do
19
+ only_files %w(en.yml)
20
+ end
21
+ end
22
+
23
+ it 'loads en locale only' do
24
+ expect(load_locales).to eq ({
25
+ en: { translation: locale_en }
26
+ })
27
+ end
28
+ end
15
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_locales_jsonizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,8 +93,10 @@ files:
93
93
  - LICENSE
94
94
  - README.md
95
95
  - Rakefile
96
+ - config/initializers/yaml_locales_jsonizer.rb
96
97
  - lib/yaml_locales_jsonizer.rb
97
98
  - lib/yaml_locales_jsonizer/action_view/helper.rb
99
+ - lib/yaml_locales_jsonizer/config.rb
98
100
  - lib/yaml_locales_jsonizer/engine.rb
99
101
  - lib/yaml_locales_jsonizer/loader.rb
100
102
  - lib/yaml_locales_jsonizer/styles.rb