vocab 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/lib/vocab/validator/android.rb +5 -0
- data/lib/vocab/validator/base.rb +6 -0
- data/lib/vocab/validator/rails.rb +12 -0
- data/lib/vocab/version.rb +1 -1
- data/spec/data/rails/locales/bom.yml +1 -0
- data/spec/validator/base_spec.rb +15 -9
- data/spec/validator/rails_spec.rb +22 -3
- metadata +12 -10
data/CHANGELOG.md
CHANGED
data/lib/vocab/validator/base.rb
CHANGED
@@ -9,6 +9,7 @@ module Vocab
|
|
9
9
|
files = files_to_validate
|
10
10
|
Vocab.ui.say( "#{files.size} file(s) to validate in #{@locales_dir}" )
|
11
11
|
files.each do |path|
|
12
|
+
ok &&= pre_validate( path )
|
12
13
|
validation = validate_file( path )
|
13
14
|
print( path, validation )
|
14
15
|
ok &&= validation[ :missing ] && validation[ :missing ].empty?
|
@@ -41,6 +42,11 @@ module Vocab
|
|
41
42
|
return result
|
42
43
|
end
|
43
44
|
|
45
|
+
# Override in subclass
|
46
|
+
def pre_validate( path )
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
@@ -18,6 +18,18 @@ module Vocab
|
|
18
18
|
return Dir.glob( "#{@locales_dir}/**/*.yml" ).reject { |path| File.basename( path ) == 'en.yml' }
|
19
19
|
end
|
20
20
|
|
21
|
+
def pre_validate( path )
|
22
|
+
bom_regex = "\xEF\xBB\xBF".force_encoding("UTF-8")
|
23
|
+
File.open( path ) do |file|
|
24
|
+
content = file.read.force_encoding( "UTF-8" )
|
25
|
+
if content.match( bom_regex )
|
26
|
+
Vocab.ui.warn( "Found a leading BOM character in #{path}" )
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
return true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
21
33
|
protected
|
22
34
|
|
23
35
|
def flattened_keys( path )
|
data/lib/vocab/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
bom:
|
data/spec/validator/base_spec.rb
CHANGED
@@ -2,16 +2,16 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Vocab::Validator::Base" do
|
4
4
|
|
5
|
-
before( :each ) do
|
6
|
-
@files = [ 'foo', 'bar' ]
|
7
|
-
@good = { :missing => [], :extra => [] }
|
8
|
-
@bad = { :missing => [ 'bad' ], :extra => [] }
|
9
|
-
|
10
|
-
@validator = Vocab::Validator::Base.new
|
11
|
-
@validator.should_receive( :files_to_validate ).and_return( @files )
|
12
|
-
end
|
13
|
-
|
14
5
|
describe "validate" do
|
6
|
+
|
7
|
+
before( :each ) do
|
8
|
+
@files = [ 'foo', 'bar' ]
|
9
|
+
@good = { :missing => [], :extra => [] }
|
10
|
+
@bad = { :missing => [ 'bad' ], :extra => [] }
|
11
|
+
|
12
|
+
@validator = Vocab::Validator::Base.new
|
13
|
+
@validator.should_receive( :files_to_validate ).and_return( @files )
|
14
|
+
end
|
15
15
|
|
16
16
|
it "returns true if no files have missing keys" do
|
17
17
|
@validator.should_receive( :validate_file ).exactly( @files.size ).times.and_return( @good )
|
@@ -22,6 +22,12 @@ describe "Vocab::Validator::Base" do
|
|
22
22
|
@validator.should_receive( :validate_file ).exactly( @files.size ).times.and_return( @bad )
|
23
23
|
@validator.validate.should be_false
|
24
24
|
end
|
25
|
+
|
26
|
+
it "returns false if the pre_validate fails" do
|
27
|
+
@validator.should_receive( :validate_file ).exactly( @files.size ).times.and_return( @good )
|
28
|
+
@validator.should_receive( :pre_validate ).and_return( false )
|
29
|
+
@validator.validate.should be_false
|
30
|
+
end
|
25
31
|
|
26
32
|
end
|
27
33
|
|
@@ -7,6 +7,20 @@ describe "Vocab::Validator::Rails" do
|
|
7
7
|
@validator = Vocab::Validator::Rails.new( @locales_dir )
|
8
8
|
end
|
9
9
|
|
10
|
+
describe 'pre_validate' do
|
11
|
+
|
12
|
+
it "complains about yml files with leading BOM characters" do
|
13
|
+
File.open( "#{@locales_dir}/bom.yml", "w+" ) { |f| f.write( "\xEF\xBB\xBF".force_encoding("UTF-8") ) }
|
14
|
+
File.open( "#{@locales_dir}/bom.yml", "a" ) { |f| f.write( "bom:" ) }
|
15
|
+
|
16
|
+
bom_regex = "\xEF\xBB\xBF".force_encoding("UTF-8")
|
17
|
+
File.open( "#{@locales_dir}/bom.yml" ) { |f| f.read }.force_encoding( "UTF-8" ).match( bom_regex ).should be_true
|
18
|
+
|
19
|
+
@validator.pre_validate( "#{@locales_dir}/bom.yml" ).should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
10
24
|
describe 'validate_file' do
|
11
25
|
|
12
26
|
before( :each ) do
|
@@ -30,9 +44,14 @@ describe "Vocab::Validator::Rails" do
|
|
30
44
|
describe 'files_to_validate' do
|
31
45
|
|
32
46
|
it 'returns the locale files to validate' do
|
33
|
-
|
34
|
-
|
35
|
-
|
47
|
+
expected = ["#{@locales_dir}/bom.yml",
|
48
|
+
"#{@locales_dir}/es.yml",
|
49
|
+
"#{@locales_dir}/models/product/es.yml"]
|
50
|
+
|
51
|
+
actual = @validator.files_to_validate
|
52
|
+
|
53
|
+
actual.size.should eql( expected.size )
|
54
|
+
expected.each { |path| actual.should include( path ) }
|
36
55
|
end
|
37
56
|
|
38
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vocab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05
|
12
|
+
date: 2012-06-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152005120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152005120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152004380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152004380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2151940680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.7.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2151940680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: simplecov
|
49
|
-
requirement: &
|
49
|
+
requirement: &2151931540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2151931540
|
58
58
|
description: Export strings that need to be translated and integrate the completed
|
59
59
|
translations
|
60
60
|
email:
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- spec/data/android/translations/values-es/es-string-file.xml
|
103
103
|
- spec/data/android/write.xml
|
104
104
|
- spec/data/android/write_plurals.xml
|
105
|
+
- spec/data/rails/locales/bom.yml
|
105
106
|
- spec/data/rails/locales/en.yml
|
106
107
|
- spec/data/rails/locales/es.yml
|
107
108
|
- spec/data/rails/locales/models/product/en.yml
|
@@ -161,6 +162,7 @@ test_files:
|
|
161
162
|
- spec/data/android/translations/values-es/es-string-file.xml
|
162
163
|
- spec/data/android/write.xml
|
163
164
|
- spec/data/android/write_plurals.xml
|
165
|
+
- spec/data/rails/locales/bom.yml
|
164
166
|
- spec/data/rails/locales/en.yml
|
165
167
|
- spec/data/rails/locales/es.yml
|
166
168
|
- spec/data/rails/locales/models/product/en.yml
|