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 +4 -4
- data/config/initializers/yaml_locales_jsonizer.rb +2 -0
- data/lib/yaml_locales_jsonizer.rb +3 -0
- data/lib/yaml_locales_jsonizer/config.rb +33 -0
- data/lib/yaml_locales_jsonizer/loader.rb +4 -1
- data/lib/yaml_locales_jsonizer/version.rb +1 -1
- data/spec/shared/locale_files.rb +5 -2
- data/spec/yaml_locales_jsonizer/loader_spec.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2b1da4a8908be5e48e2b0bfcd1b9fe0d91ae1e7
|
4
|
+
data.tar.gz: 06e5dc0124d4f3dfd3aa7487b55200897114e185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaa61776598c5d31a986efe8bed8463525f88cb8e4b6d3601ffa3b85c05fc924bd1f4a49da1d945485b0458b50249e9d3e0dabb4b3f7371e9cc6f45d6bdf9104
|
7
|
+
data.tar.gz: 429619921c2d3f990b2ccecd1765f1884fc9aaf615a73c2311573d5d8f945633762b0e873cd127d1c9b8f5882b2bf1fe1c5cf77b908976441e468d54210cab2d
|
@@ -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
|
-
|
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
|
data/spec/shared/locale_files.rb
CHANGED
@@ -6,8 +6,11 @@ shared_context 'locale files' do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
before do
|
9
|
-
|
10
|
-
|
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.
|
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-
|
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
|