android_string_resources_validator 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/android_string_resources_validator.gemspec +27 -0
- data/lib/android_string_resources_validator/version.rb +3 -0
- data/lib/android_string_resources_validator.rb +75 -0
- data/spec/lib/android_string_resources_validator_spec.rb +57 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d59bc83f942aee4719a1fb7759933474ff8520f9
|
4
|
+
data.tar.gz: 3067cf6c925a63c0b84a76de598b7d6f2b2bd083
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ef20a5ab64d8a12ce49ae170a83c5612fa2144688324a782bd583ef0b5d3b3f3b9ff20e844ba942983a6842cebdf0e08f71e3853a19f9f9bf483719848a6e6c
|
7
|
+
data.tar.gz: 96f1bbe43aa23a8911e9ab89ab6c2433030593554643c8a743df36b42ee758cf7acd7985b4a1c9345ecdc02fffa758997d4f1b86ba104142381190bb6e7223f9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Karl Eklund
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# AndroidStringResourcesValidator
|
2
|
+
|
3
|
+
[](https://circleci.com/gh/magplus/android_string_resources_validator.png?circle-token=4ad6dc72948c7f0cdc31b92cf292142d599be4ce)
|
4
|
+
|
5
|
+
Validates an Android strings.xml resource file against the specification at
|
6
|
+
http://developer.android.com/guide/topics/resources/string-resource.html
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'android_string_resources_validator'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install android_string_resources_validator
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
strings_xml = %q{<resources><string name="hello">It\'s all right</string></resources>}
|
26
|
+
validator = AndroidStringResourcesValidator.new(strings_xml)
|
27
|
+
validator.valid? # => true
|
28
|
+
|
29
|
+
strings_xml = %q{<resources><string name="hello">It's no good</string></resources>}
|
30
|
+
validator = AndroidStringResourcesValidator.new(strings_xml)
|
31
|
+
validator.valid? # => false
|
32
|
+
validator.errors # => ["Apostrophes must be escaped"]
|
33
|
+
|
34
|
+
strings_xml = %q{<foo><string name="string_name">text_string</string></foo>}
|
35
|
+
validator = AndroidStringResourcesValidator.new(strings_xml)
|
36
|
+
validator.valid? # => false
|
37
|
+
validator.errors # => ["Not a string resource document"]
|
38
|
+
|
39
|
+
strings_xml = %q{<foo>}
|
40
|
+
validator = AndroidStringResourcesValidator.new(strings_xml)
|
41
|
+
validator.valid? # => false
|
42
|
+
validator.errors # => ["Not a valid XML document"]
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( http://github.com/magplus/android_string_resources_validator/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'android_string_resources_validator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "android_string_resources_validator"
|
8
|
+
spec.version = AndroidStringResourcesValidator::VERSION
|
9
|
+
spec.authors = ["Karl Eklund", "Lennart Fridén"]
|
10
|
+
spec.email = ["backend@magplus.com"]
|
11
|
+
spec.summary = %q{Validates an Android strings.xml file.}
|
12
|
+
spec.description = %q{Validates an Android string resource file against the specification at http://developer.android.com/guide/topics/resources/string-resource.html.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "nokogiri"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "android_string_resources_validator/version"
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
class AndroidStringResourcesValidator
|
5
|
+
def initialize(string)
|
6
|
+
@string = string
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
errors.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def errors
|
14
|
+
strings.map(&:error).compact
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :string
|
20
|
+
|
21
|
+
def strings
|
22
|
+
doc.xpath('//resources/string').map do |element|
|
23
|
+
ElementString.new(element.text)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def doc
|
28
|
+
Nokogiri::XML(@string)
|
29
|
+
end
|
30
|
+
|
31
|
+
class ElementString
|
32
|
+
def initialize(string)
|
33
|
+
@string = string
|
34
|
+
end
|
35
|
+
|
36
|
+
def error
|
37
|
+
return "Apostrophes must be escaped" if unsurrounded_contains_unescaped_single_quotes
|
38
|
+
return "Double quotes must be escaped" if unsurrounded_contains_unescaped_double_quotes
|
39
|
+
return "Double quotes must be escaped or surrounded by single quotes" if string_without_double_quotes_contains_unescaped_double_quotes
|
40
|
+
return "Single quotes must be escaped or surrounded by double quotes" if string_without_single_quotes_contains_unescaped_single_quotes
|
41
|
+
end
|
42
|
+
|
43
|
+
def unsurrounded_contains_unescaped_single_quotes
|
44
|
+
!surrounded_by_double_quotes && !surrounded_by_single_quotes && contains_unescaped_single_quotes
|
45
|
+
end
|
46
|
+
|
47
|
+
def unsurrounded_contains_unescaped_double_quotes
|
48
|
+
!surrounded_by_double_quotes && !surrounded_by_single_quotes && contains_unescaped_double_quotes
|
49
|
+
end
|
50
|
+
|
51
|
+
def surrounded_by_double_quotes
|
52
|
+
@string[/\A".*"\z/]
|
53
|
+
end
|
54
|
+
|
55
|
+
def contains_unescaped_single_quotes
|
56
|
+
@string[/[^\\]'/]
|
57
|
+
end
|
58
|
+
|
59
|
+
def surrounded_by_single_quotes
|
60
|
+
@string[/\A'.*'\z/]
|
61
|
+
end
|
62
|
+
|
63
|
+
def contains_unescaped_double_quotes
|
64
|
+
@string[/[^\\]"/]
|
65
|
+
end
|
66
|
+
|
67
|
+
def string_without_single_quotes_contains_unescaped_single_quotes
|
68
|
+
@string[/\A'.*[^\\]'.*'\z/]
|
69
|
+
end
|
70
|
+
|
71
|
+
def string_without_double_quotes_contains_unescaped_double_quotes
|
72
|
+
@string[/\A".*[^\\]".*"\z/]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'android_string_resources_validator'
|
2
|
+
|
3
|
+
describe AndroidStringResourcesValidator do
|
4
|
+
specify %q{"This'll work"} do
|
5
|
+
assert_valid %q{"This'll work"}
|
6
|
+
end
|
7
|
+
|
8
|
+
specify %q{This\'ll also work} do
|
9
|
+
assert_valid %q{This\'ll also work}
|
10
|
+
end
|
11
|
+
|
12
|
+
specify %q{This doesn't work} do
|
13
|
+
assert_invalid %q{This doesn't work}, "Apostrophes must be escaped"
|
14
|
+
end
|
15
|
+
|
16
|
+
specify %q{'A lonely " seems weird, but is allowed'} do
|
17
|
+
assert_valid %q{'A lonely " seems weird, but is allowed'}
|
18
|
+
end
|
19
|
+
|
20
|
+
specify %q{A lonely \" seems weird, but is allowed} do
|
21
|
+
assert_valid %q{A lonely \" seems weird, but is allowed}
|
22
|
+
end
|
23
|
+
|
24
|
+
specify %q{A lonely " is not allowed} do
|
25
|
+
assert_invalid %q{A lonely " is not allowed}, "Double quotes must be escaped"
|
26
|
+
end
|
27
|
+
|
28
|
+
specify %q{"A lonely " is not allowed"} do
|
29
|
+
assert_invalid %q{"A lonely " is not allowed"}, "Double quotes must be escaped or surrounded by single quotes"
|
30
|
+
end
|
31
|
+
|
32
|
+
specify %q{'A lonely ' is not allowed'} do
|
33
|
+
assert_invalid %q{'A lonely ' is not allowed'}, "Single quotes must be escaped or surrounded by double quotes"
|
34
|
+
end
|
35
|
+
|
36
|
+
specify %q{Special identifiers such as %& and %d are allowed} do
|
37
|
+
assert_valid %q{Special identifiers such as %& and %d are allowed}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def strings_xml(string)
|
43
|
+
%Q{<resources><string name="hello">#{string}</string></resources>}
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_valid(string)
|
47
|
+
validator = AndroidStringResourcesValidator.new(strings_xml(string))
|
48
|
+
validator.errors.should == []
|
49
|
+
validator.should be_valid
|
50
|
+
end
|
51
|
+
|
52
|
+
def assert_invalid(string, error_message)
|
53
|
+
validator = AndroidStringResourcesValidator.new(strings_xml(string))
|
54
|
+
validator.should_not be_valid
|
55
|
+
validator.errors.should == Array(error_message)
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: android_string_resources_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Karl Eklund
|
8
|
+
- Lennart Fridén
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.5'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.5'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard-rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Validates an Android string resource file against the specification at
|
85
|
+
http://developer.android.com/guide/topics/resources/string-resource.html.
|
86
|
+
email:
|
87
|
+
- backend@magplus.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- Guardfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- android_string_resources_validator.gemspec
|
100
|
+
- lib/android_string_resources_validator.rb
|
101
|
+
- lib/android_string_resources_validator/version.rb
|
102
|
+
- spec/lib/android_string_resources_validator_spec.rb
|
103
|
+
homepage: ''
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.1.11
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Validates an Android strings.xml file.
|
127
|
+
test_files:
|
128
|
+
- spec/lib/android_string_resources_validator_spec.rb
|