rack-http-accept-language 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/LICENSE.md +9 -0
- data/README.md +12 -1
- data/lib/rack-http-accept-language/parser.rb +1 -1
- data/rack-http-accept-language.gemspec +2 -1
- data/spec/parser_spec.rb +11 -2
- metadata +5 -4
- data/Gemfile.lock +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0a8f38f11bdfe2d20a5001d1f7b03c5d81fa3fd
|
4
|
+
data.tar.gz: ae0529d85ef2739461259a684588f6060910b90d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93634a6a9929c56e58771befddcac444e079595e4e919cd565db703ebfa6215cd83dbf4aafc9c994a2efea1bd2707ec8665fa7e6436f5ece48589b4286f65407
|
7
|
+
data.tar.gz: e1a4e1e35f4459b26ac1e4f5d02c1d6c7509ce048a1c6ac0f5b8a712863d6e940d599b5b2fc7f25c269fbe09278d4d0f40f57ecf4f7274c990adbc2010e16882
|
data/.gitignore
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Bennet Palluthe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# RackHttpAcceptLanguage
|
2
2
|
[](https://travis-ci.org/kaeuferportal/rack-http-accept-language)
|
3
|
+
[](https://badge.fury.io/rb/rack-http-accept-language)
|
3
4
|
|
4
5
|
## Possible Methods
|
5
6
|
|
@@ -14,7 +15,7 @@ rack_http_accept_lanugages
|
|
14
15
|
|
15
16
|
## How you can use it with Sinatra
|
16
17
|
|
17
|
-
```
|
18
|
+
``` ruby
|
18
19
|
class App < Sinatra::Base
|
19
20
|
use RackHttpAcceptLanguage::Middleware
|
20
21
|
|
@@ -24,6 +25,12 @@ class App < Sinatra::Base
|
|
24
25
|
end
|
25
26
|
```
|
26
27
|
|
28
|
+
## How you use it with Rails
|
29
|
+
|
30
|
+
Add the following line to your ``application.rb``
|
31
|
+
``` ruby
|
32
|
+
config.middleware.use RackHttpAcceptLanguage::Middleware
|
33
|
+
```
|
27
34
|
|
28
35
|
## Installation
|
29
36
|
|
@@ -34,3 +41,7 @@ gem 'rack-http-accept-language'
|
|
34
41
|
```
|
35
42
|
|
36
43
|
Run `bundle install` to install it.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
RackHttpAcceptLanguage is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
@@ -42,7 +42,7 @@ module RackHttpAcceptLanguage
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def handle_language(language, qvalue, memo)
|
45
|
-
language = language.downcase.gsub(/-[a-z0-9]+$/i, &:upcase)
|
45
|
+
language = language.strip.downcase.gsub(/-[a-z0-9]+$/i, &:upcase)
|
46
46
|
qvalue = qvalue ? qvalue.to_f : 1.0
|
47
47
|
|
48
48
|
if memo[qvalue].nil?
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'rack-http-accept-language'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.1'
|
5
5
|
|
6
6
|
if s.respond_to? :required_rubygems_version=
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new('>= 1.2')
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.summary = 'http accept language handler'
|
26
26
|
s.description = 'http accept language handler'
|
27
27
|
s.homepage = 'https://github.com/kaeuferportal/rack-http-accept-language'
|
28
|
+
s.license = 'MIT'
|
28
29
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -3,9 +3,10 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe RackHttpAcceptLanguage::Parser do
|
5
5
|
context 'without wildcard' do
|
6
|
+
subject(:parser) { described_class.new(http_accept_language) }
|
7
|
+
|
6
8
|
context 'no upcase handling necessary' do
|
7
9
|
let(:http_accept_language) { 'en-US,en-GB;q=0.6,en;q=0.8' }
|
8
|
-
subject(:parser) { described_class.new(http_accept_language) }
|
9
10
|
|
10
11
|
it 'preferred language' do
|
11
12
|
expected_array = 'en-US'
|
@@ -20,7 +21,6 @@ describe RackHttpAcceptLanguage::Parser do
|
|
20
21
|
|
21
22
|
context 'upcase necessary' do
|
22
23
|
let(:http_accept_language) { 'en-us,en-GB;q=0.6,en;q=0.8' }
|
23
|
-
subject(:parser) { described_class.new(http_accept_language) }
|
24
24
|
|
25
25
|
it 'preferred language' do
|
26
26
|
expected_array = 'en-US'
|
@@ -32,6 +32,15 @@ describe RackHttpAcceptLanguage::Parser do
|
|
32
32
|
expect(parser.preferred_languages).to eq expected_array
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
context 'with spaces' do
|
37
|
+
let(:http_accept_language) { 'en-US, en-GB;q=0.6, en;q=0.8' }
|
38
|
+
|
39
|
+
it 'strips unneccessary spaces' do
|
40
|
+
expected_array = ['en-US', 'en', 'en-GB']
|
41
|
+
expect(parser.preferred_languages).to eq expected_array
|
42
|
+
end
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
context 'with wildcard' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-http-accept-language
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bennet Palluthe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -97,7 +97,7 @@ files:
|
|
97
97
|
- ".rubocop.yml"
|
98
98
|
- ".travis.yml"
|
99
99
|
- Gemfile
|
100
|
-
-
|
100
|
+
- LICENSE.md
|
101
101
|
- README.md
|
102
102
|
- lib/rack-http-accept-language.rb
|
103
103
|
- lib/rack-http-accept-language/middleware.rb
|
@@ -107,7 +107,8 @@ files:
|
|
107
107
|
- spec/parser_spec.rb
|
108
108
|
- spec/spec_helper.rb
|
109
109
|
homepage: https://github.com/kaeuferportal/rack-http-accept-language
|
110
|
-
licenses:
|
110
|
+
licenses:
|
111
|
+
- MIT
|
111
112
|
metadata: {}
|
112
113
|
post_install_message:
|
113
114
|
rdoc_options: []
|
data/Gemfile.lock
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rack-http-accept-language (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.2.0)
|
10
|
-
codeclimate-test-reporter (0.4.8)
|
11
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
12
|
-
coderay (1.1.1)
|
13
|
-
diff-lcs (1.2.5)
|
14
|
-
docile (1.1.5)
|
15
|
-
json (1.8.3)
|
16
|
-
method_source (0.8.2)
|
17
|
-
parser (2.3.0.6)
|
18
|
-
ast (~> 2.2)
|
19
|
-
powerpack (0.1.1)
|
20
|
-
pry (0.10.3)
|
21
|
-
coderay (~> 1.1.0)
|
22
|
-
method_source (~> 0.8.1)
|
23
|
-
slop (~> 3.4)
|
24
|
-
rack (1.6.4)
|
25
|
-
rack-test (0.6.3)
|
26
|
-
rack (>= 1.0)
|
27
|
-
rainbow (2.1.0)
|
28
|
-
rspec (3.4.0)
|
29
|
-
rspec-core (~> 3.4.0)
|
30
|
-
rspec-expectations (~> 3.4.0)
|
31
|
-
rspec-mocks (~> 3.4.0)
|
32
|
-
rspec-core (3.4.4)
|
33
|
-
rspec-support (~> 3.4.0)
|
34
|
-
rspec-expectations (3.4.0)
|
35
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.4.0)
|
37
|
-
rspec-mocks (3.4.1)
|
38
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.4.0)
|
40
|
-
rspec-support (3.4.1)
|
41
|
-
rubocop (0.38.0)
|
42
|
-
parser (>= 2.3.0.6, < 3.0)
|
43
|
-
powerpack (~> 0.1)
|
44
|
-
rainbow (>= 1.99.1, < 3.0)
|
45
|
-
ruby-progressbar (~> 1.7)
|
46
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
47
|
-
ruby-progressbar (1.7.5)
|
48
|
-
simplecov (0.11.2)
|
49
|
-
docile (~> 1.1.0)
|
50
|
-
json (~> 1.8)
|
51
|
-
simplecov-html (~> 0.10.0)
|
52
|
-
simplecov-html (0.10.0)
|
53
|
-
slop (3.6.0)
|
54
|
-
unicode-display_width (1.0.2)
|
55
|
-
|
56
|
-
PLATFORMS
|
57
|
-
ruby
|
58
|
-
|
59
|
-
DEPENDENCIES
|
60
|
-
codeclimate-test-reporter (~> 0.4.8)
|
61
|
-
pry (~> 0.10.3)
|
62
|
-
rack-http-accept-language!
|
63
|
-
rack-test (~> 0.6.3)
|
64
|
-
rspec (~> 3.3, >= 3.3.0)
|
65
|
-
rubocop (~> 0.38.0)
|
66
|
-
|
67
|
-
BUNDLED WITH
|
68
|
-
1.11.2
|