browsernizer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +4 -0
- data/README.md +2 -0
- data/lib/browsernizer/browser_version.rb +1 -1
- data/lib/browsernizer/router.rb +20 -33
- data/lib/browsernizer/version.rb +1 -1
- metadata +8 -8
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Browsernizer
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/browsernizer.png)](http://badge.fury.io/rb/browsernizer)
|
4
|
+
|
3
5
|
Want friendly "please upgrade your browser" page? This gem is for you.
|
4
6
|
|
5
7
|
You can redirect your visitors to any page you like (static or dynamic).
|
data/lib/browsernizer/router.rb
CHANGED
@@ -10,37 +10,26 @@ module Browsernizer
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def call(env)
|
13
|
-
|
14
|
-
|
15
|
-
"supported" =>
|
13
|
+
raw_browser, browser = get_browsers(env)
|
14
|
+
env["browsernizer"] = {
|
15
|
+
"supported" => supported?(raw_browser, browser),
|
16
16
|
"browser" => browser.name.to_s,
|
17
17
|
"version" => browser.version.to_s
|
18
18
|
}
|
19
|
-
|
19
|
+
redirect_request(env) || @app.call(env)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
|
-
def handle_request
|
24
|
-
@env["browsernizer"]["supported"] = false if unsupported?
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
elsif on_redirection_path?
|
33
|
-
throw :response, redirect_to_root
|
34
|
-
end
|
35
|
-
end
|
36
|
-
propagate_request
|
24
|
+
def redirect_request(env)
|
25
|
+
return if path_excluded?(env)
|
26
|
+
if !env["browsernizer"]["supported"]
|
27
|
+
return redirect_to_specified if @config.get_location && !on_redirection_path?(env)
|
28
|
+
elsif on_redirection_path?(env)
|
29
|
+
return redirect_to_root
|
37
30
|
end
|
38
31
|
end
|
39
32
|
|
40
|
-
def propagate_request
|
41
|
-
@app.call(@env)
|
42
|
-
end
|
43
|
-
|
44
33
|
def redirect_to_specified
|
45
34
|
[307, {"Content-Type" => "text/plain", "Location" => @config.get_location}, []]
|
46
35
|
end
|
@@ -49,25 +38,23 @@ module Browsernizer
|
|
49
38
|
[303, {"Content-Type" => "text/plain", "Location" => "/"}, []]
|
50
39
|
end
|
51
40
|
|
52
|
-
def path_excluded?
|
53
|
-
@config.excluded?
|
54
|
-
end
|
55
|
-
|
56
|
-
def on_redirection_path?
|
57
|
-
@config.get_location && @config.get_location == @env["PATH_INFO"]
|
41
|
+
def path_excluded?(env)
|
42
|
+
@config.excluded? env["PATH_INFO"]
|
58
43
|
end
|
59
44
|
|
60
|
-
def
|
61
|
-
|
45
|
+
def on_redirection_path?(env)
|
46
|
+
@config.get_location && @config.get_location == env["PATH_INFO"]
|
62
47
|
end
|
63
48
|
|
64
|
-
def
|
65
|
-
Browser.new
|
49
|
+
def get_browsers(env)
|
50
|
+
raw_browser = ::Browser.new :ua => env["HTTP_USER_AGENT"]
|
51
|
+
browser = Browsernizer::Browser.new raw_browser.name.to_s, raw_browser.full_version.to_s
|
52
|
+
[raw_browser, browser]
|
66
53
|
end
|
67
54
|
|
68
55
|
# supported by default
|
69
|
-
def
|
70
|
-
|
56
|
+
def supported?(raw_browser, browser)
|
57
|
+
!@config.get_supported.any? do |requirement|
|
71
58
|
supported = if requirement.respond_to?(:call)
|
72
59
|
requirement.call(raw_browser)
|
73
60
|
else
|
data/lib/browsernizer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browsernizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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:
|
12
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70152071474760 !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: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70152071474760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70152071473880 !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: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70152071473880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: browser
|
38
|
-
requirement: &
|
38
|
+
requirement: &70152071472940 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.1.4
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70152071472940
|
47
47
|
description: Rack middleware for redirecting unsupported user agents to "please upgrade"
|
48
48
|
page
|
49
49
|
email:
|