browsernizer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/lib/browsernizer/config.rb +8 -2
- data/lib/browsernizer/router.rb +11 -3
- data/lib/browsernizer/version.rb +1 -1
- data/spec/browsernizer/router_spec.rb +16 -0
- metadata +9 -9
data/README.md
CHANGED
@@ -46,6 +46,15 @@ If you wish to completely prevent some browsers from accessing website
|
|
46
46
|
|
47
47
|
config.supported "Internet Explorer", false
|
48
48
|
|
49
|
+
There is also an option to provide block for more advanced checking.
|
50
|
+
[UserAgent object](https://github.com/josh/useragent/tree/master/lib) will be
|
51
|
+
passed to it. If you wish to state that *mobile safari* is not supported, you
|
52
|
+
can declare it like this:
|
53
|
+
|
54
|
+
config.supported do |agent|
|
55
|
+
!(agent.browser == "Safari" && agent.mobile?)
|
56
|
+
end
|
57
|
+
|
49
58
|
Specifying location is optional. If you prefer handling unsupported browsers on
|
50
59
|
your own, you can access browsernizer info from `request.env['browsernizer']`
|
51
60
|
within your controller.
|
data/lib/browsernizer/config.rb
CHANGED
@@ -8,8 +8,14 @@ module Browsernizer
|
|
8
8
|
@handler = lambda { }
|
9
9
|
end
|
10
10
|
|
11
|
-
def supported(
|
12
|
-
|
11
|
+
def supported(*args, &block)
|
12
|
+
if args.length == 2
|
13
|
+
@supported << Browser.new(args[0], args[1])
|
14
|
+
elsif block_given?
|
15
|
+
@supported << block
|
16
|
+
else
|
17
|
+
raise ArgumentError, "accepts either (browser, version) or block"
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
def location(path)
|
data/lib/browsernizer/router.rb
CHANGED
@@ -57,15 +57,23 @@ module Browsernizer
|
|
57
57
|
@config.get_location && @config.get_location == @env["PATH_INFO"]
|
58
58
|
end
|
59
59
|
|
60
|
+
def raw_agent
|
61
|
+
::UserAgent.parse @env["HTTP_USER_AGENT"]
|
62
|
+
end
|
63
|
+
|
60
64
|
def agent
|
61
|
-
|
62
|
-
Browser.new a.browser.to_s, a.version.to_s
|
65
|
+
Browser.new raw_agent.browser.to_s, raw_agent.version.to_s
|
63
66
|
end
|
64
67
|
|
65
68
|
# supported by default
|
66
69
|
def unsupported?
|
67
70
|
@config.get_supported.any? do |requirement|
|
68
|
-
|
71
|
+
supported = if requirement.respond_to?(:call)
|
72
|
+
requirement.call(raw_agent)
|
73
|
+
else
|
74
|
+
agent.meets?(requirement)
|
75
|
+
end
|
76
|
+
supported === false
|
69
77
|
end
|
70
78
|
end
|
71
79
|
end
|
data/lib/browsernizer/version.rb
CHANGED
@@ -8,6 +8,9 @@ describe Browsernizer::Router do
|
|
8
8
|
Browsernizer::Router.new(app) do |config|
|
9
9
|
config.supported "Firefox", false
|
10
10
|
config.supported "Chrome", "7.1"
|
11
|
+
config.supported do |agent|
|
12
|
+
!(agent.browser == "Safari" && agent.mobile?)
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -103,6 +106,15 @@ describe Browsernizer::Router do
|
|
103
106
|
it_behaves_like "unsupported browser"
|
104
107
|
end
|
105
108
|
|
109
|
+
context "Unsupported by proc" do
|
110
|
+
before do
|
111
|
+
@env = default_env.merge({
|
112
|
+
"HTTP_USER_AGENT" => mobile_safari_agent
|
113
|
+
})
|
114
|
+
end
|
115
|
+
it_behaves_like "unsupported browser"
|
116
|
+
end
|
117
|
+
|
106
118
|
def chrome_agent(version)
|
107
119
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/#{version} Safari/535.7"
|
108
120
|
end
|
@@ -111,4 +123,8 @@ describe Browsernizer::Router do
|
|
111
123
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.1) Gecko/20100101 Firefox/#{version}"
|
112
124
|
end
|
113
125
|
|
126
|
+
def mobile_safari_agent
|
127
|
+
"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419"
|
128
|
+
end
|
129
|
+
|
114
130
|
end
|
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.1.
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2012-04-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70114364841740 !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: *70114364841740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70114364841180 !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: *70114364841180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: useragent
|
38
|
-
requirement: &
|
38
|
+
requirement: &70114364840480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.4.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70114364840480
|
47
47
|
description: Rack middleware for redirecting unsupported user agents to "please upgrade"
|
48
48
|
page
|
49
49
|
email:
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project: browsernizer
|
94
|
-
rubygems_version: 1.8.
|
94
|
+
rubygems_version: 1.8.10
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
97
|
summary: Want friendly "please upgrade your browser" page? This gem is for you.
|