browser 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +4 -0
- data/README.md +20 -31
- data/lib/browser/base.rb +5 -0
- data/lib/browser/version.rb +1 -1
- data/test/test_helper.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35cb9e029740dd22fac2f08ea933fb541b914ddc3d437f49e2402f68be7aecb3
|
4
|
+
data.tar.gz: 534a21b9b6892178c02976d19fe8ef81e9746783ac87469239efb9e8033bfaeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe9062f778c871766bddce4738c63ad005e0fc6310c46b0505f78da1c304e5d2f0359d8c2685727203876f8b83bf7ee06fc7dfa6b2f5fb6da719cf60bd5f80a7
|
7
|
+
data.tar.gz: ecce9f6468c7e5cfb11e47aeeaa68c44d8be5ad6b4e6e34cc9f64721dbaf0adae1514cb8b57097ec679481da7286713468fa4ac88de397190179bbf13ef42331
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,6 @@ browser.ie?(6) # detect specific IE version
|
|
34
34
|
browser.ie?([">8", "<10"]) # detect specific IE (IE9).
|
35
35
|
browser.known? # has the browser been successfully detected?
|
36
36
|
browser.meta # an array with several attributes
|
37
|
-
browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
|
38
37
|
browser.name # readable browser name
|
39
38
|
browser.nokia?
|
40
39
|
browser.opera?
|
@@ -145,23 +144,26 @@ browser.mobile? #=> false
|
|
145
144
|
- For a list of device detections, check [lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
|
146
145
|
- For a list of bot detections, check [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
|
147
146
|
|
148
|
-
###
|
147
|
+
### Detecting modern browsers
|
149
148
|
|
150
|
-
|
151
|
-
|
152
|
-
* Chrome 65+
|
153
|
-
* Safari 10+
|
154
|
-
* Firefox 52+
|
155
|
-
* IE11+
|
156
|
-
* Microsoft Edge 39+
|
157
|
-
* Opera 50+
|
158
|
-
|
159
|
-
You can define your own rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.
|
149
|
+
To detect whether a browser can be considered as modern or not, create a method that abstracts your versioning constraints. The following example will consider any of the following browsers as a modern:
|
160
150
|
|
161
151
|
```ruby
|
162
|
-
#
|
163
|
-
Browser.
|
164
|
-
|
152
|
+
# Expects an Browser instance,
|
153
|
+
# like in `Browser.new(user_agent, accept_language: language)`.
|
154
|
+
def modern_browser?(browser)
|
155
|
+
[
|
156
|
+
browser.chrome? && browser.version.to_i >= 65,
|
157
|
+
browser.safari? && browser.version.to_i >= 10,
|
158
|
+
browser.firefox? && browser.version.to_i >= 52,
|
159
|
+
browser.ie? && browser.version.to_i >= 11 && !browser.compatibility_view?,
|
160
|
+
browser.edge? && browser.version.to_i >= 15,
|
161
|
+
browser.opera? && browser.version.to_i >= 50,
|
162
|
+
browser.facebook?
|
163
|
+
&& browser.safari_webapp_mode?
|
164
|
+
&& browser.webkit_full_version.to_i >= 602
|
165
|
+
].any?
|
166
|
+
end
|
165
167
|
```
|
166
168
|
|
167
169
|
### Rails integration
|
@@ -240,9 +242,6 @@ browser.msie_full_version
|
|
240
242
|
|
241
243
|
browser.compatibility_view?
|
242
244
|
#=> true
|
243
|
-
|
244
|
-
browser.modern?
|
245
|
-
#=> false
|
246
245
|
```
|
247
246
|
|
248
247
|
This behavior changed in `v1.0.0`; previously there wasn't a way of getting the real browser version.
|
@@ -298,7 +297,7 @@ You can use the `Browser::Middleware` to redirect user agents.
|
|
298
297
|
|
299
298
|
```ruby
|
300
299
|
use Browser::Middleware do
|
301
|
-
redirect_to "/upgrade"
|
300
|
+
redirect_to "/upgrade" if browser.ie?
|
302
301
|
end
|
303
302
|
```
|
304
303
|
|
@@ -306,17 +305,7 @@ If you're using Rails, you can use the route helper methods. Just add something
|
|
306
305
|
|
307
306
|
```ruby
|
308
307
|
Rails.configuration.middleware.use Browser::Middleware do
|
309
|
-
redirect_to upgrade_path
|
310
|
-
end
|
311
|
-
```
|
312
|
-
|
313
|
-
Notice that you can have multiple conditionals.
|
314
|
-
|
315
|
-
```ruby
|
316
|
-
Rails.configuration.middleware.use Browser::Middleware do
|
317
|
-
next if browser.bot.search_engine?
|
318
|
-
redirect_to upgrade_path(browser: "oldie") if browser.ie? && !browser.modern?
|
319
|
-
redirect_to upgrade_path(browser: "oldfx") if browser.firefox? && !browser.modern?
|
308
|
+
redirect_to upgrade_path if browser.ie?
|
320
309
|
end
|
321
310
|
```
|
322
311
|
|
@@ -324,7 +313,7 @@ If you need access to the `Rack::Request` object (e.g. to exclude a path), you c
|
|
324
313
|
|
325
314
|
```ruby
|
326
315
|
Rails.configuration.middleware.use Browser::Middleware do
|
327
|
-
redirect_to upgrade_path
|
316
|
+
redirect_to upgrade_path if browser.ie? && request.env["PATH_INFO"] != "/exclude_me"
|
328
317
|
end
|
329
318
|
```
|
330
319
|
|
data/lib/browser/base.rb
CHANGED
@@ -52,6 +52,11 @@ module Browser
|
|
52
52
|
|
53
53
|
# Return true if browser is modern (Webkit, Firefox 17+, IE9+, Opera 12+).
|
54
54
|
def modern?
|
55
|
+
warn <<~TEXT
|
56
|
+
Browser::Base#modern? is now deprecated.
|
57
|
+
Check https://github.com/fnando/browser/issues/435 for details.
|
58
|
+
TEXT
|
59
|
+
|
55
60
|
Browser.modern_rules.any? {|rule| rule === self } # rubocop:disable Style/CaseEquality
|
56
61
|
end
|
57
62
|
|
data/lib/browser/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|