browser 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/.travis.yml +8 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +70 -38
- data/README.md +114 -0
- data/Rakefile +12 -10
- data/browser.gemspec +2 -4
- data/config.ru +2 -0
- data/gemfiles/rails3.gemfile +4 -0
- data/gemfiles/rails3.gemfile.lock +111 -0
- data/lib/browser.rb +57 -283
- data/lib/browser/action_controller.rb +9 -7
- data/lib/browser/meta/base.rb +20 -0
- data/lib/browser/meta/generic_browser.rb +9 -0
- data/lib/browser/meta/id.rb +9 -0
- data/lib/browser/meta/ie.rb +18 -0
- data/lib/browser/meta/ios.rb +9 -0
- data/lib/browser/meta/mobile.rb +9 -0
- data/lib/browser/meta/modern.rb +9 -0
- data/lib/browser/meta/platform.rb +9 -0
- data/lib/browser/meta/safari.rb +9 -0
- data/lib/browser/meta/webkit.rb +9 -0
- data/lib/browser/methods/devices.rb +33 -0
- data/lib/browser/methods/ie.rb +40 -0
- data/lib/browser/methods/language.rb +131 -0
- data/lib/browser/methods/mobile.rb +23 -0
- data/lib/browser/methods/platform.rb +54 -0
- data/lib/browser/middleware.rb +43 -0
- data/lib/browser/middleware/context.rb +20 -0
- data/lib/browser/middleware/context/additions.rb +16 -0
- data/lib/browser/middleware/context/url_methods.rb +13 -0
- data/lib/browser/rails.rb +14 -0
- data/lib/browser/version.rb +2 -2
- data/test/browser_test.rb +220 -74
- data/test/middleware_test.rb +32 -0
- data/test/sample_app.rb +27 -0
- data/test/test_helper.rb +2 -1
- metadata +43 -57
- data/README.rdoc +0 -75
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f90b0344537f71e69a359b33edbcebe06ee932f
|
4
|
+
data.tar.gz: 6e6caba603576500ab20f2b643be80904fc5e1d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75b78cc40248cc1a32c0acc7c92a4ea7375acc1a9324d2a1120d6538a217bf9c3b2fce3de825516dba71375ee76005db283fe91f44f4dea627b92781f9097e23
|
7
|
+
data.tar.gz: 580e766794ff26827365750195a2f42e068b745a28f531744f0b2116526a5bbf7f3d0956bd02d4cbd27cf7e2fa4e30296e53b6d44327e1777d158247a7b7c965
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,52 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
browser (0.
|
4
|
+
browser (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
actionmailer (4.0.0)
|
10
|
+
actionpack (= 4.0.0)
|
11
|
+
mail (~> 2.5.3)
|
12
|
+
actionpack (4.0.0)
|
13
|
+
activesupport (= 4.0.0)
|
14
|
+
builder (~> 3.1.0)
|
13
15
|
erubis (~> 2.7.0)
|
14
|
-
|
15
|
-
rack (~>
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
rack (~> 1.5.2)
|
17
|
+
rack-test (~> 0.6.2)
|
18
|
+
activemodel (4.0.0)
|
19
|
+
activesupport (= 4.0.0)
|
20
|
+
builder (~> 3.1.0)
|
21
|
+
activerecord (4.0.0)
|
22
|
+
activemodel (= 4.0.0)
|
23
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
24
|
+
activesupport (= 4.0.0)
|
25
|
+
arel (~> 4.0.0)
|
26
|
+
activerecord-deprecated_finders (1.0.3)
|
27
|
+
activesupport (4.0.0)
|
28
|
+
i18n (~> 0.6, >= 0.6.4)
|
29
|
+
minitest (~> 4.2)
|
30
|
+
multi_json (~> 1.3)
|
31
|
+
thread_safe (~> 0.1)
|
32
|
+
tzinfo (~> 0.3.37)
|
33
|
+
arel (4.0.0)
|
34
|
+
atomic (1.1.10)
|
25
35
|
awesome_print (1.1.0)
|
26
|
-
builder (3.
|
27
|
-
coderay (1.0.
|
36
|
+
builder (3.1.4)
|
37
|
+
coderay (1.0.9)
|
28
38
|
erubis (2.7.0)
|
29
|
-
hike (1.2.
|
30
|
-
i18n (0.6.
|
31
|
-
|
32
|
-
|
39
|
+
hike (1.2.3)
|
40
|
+
i18n (0.6.4)
|
41
|
+
mail (2.5.4)
|
42
|
+
mime-types (~> 1.16)
|
43
|
+
treetop (~> 1.4.8)
|
33
44
|
method_source (0.8.1)
|
34
|
-
|
35
|
-
|
45
|
+
mime-types (1.23)
|
46
|
+
minitest (4.7.5)
|
47
|
+
multi_json (1.7.7)
|
48
|
+
polyglot (0.3.3)
|
49
|
+
pry (0.9.12.2)
|
36
50
|
coderay (~> 1.0.5)
|
37
51
|
method_source (~> 0.8)
|
38
52
|
slop (~> 3.4)
|
@@ -43,32 +57,50 @@ GEM
|
|
43
57
|
pry-remote
|
44
58
|
pry-nav (0.2.3)
|
45
59
|
pry (~> 0.9.10)
|
46
|
-
pry-remote (0.1.
|
60
|
+
pry-remote (0.1.7)
|
47
61
|
pry (~> 0.9)
|
48
62
|
slop (~> 3.0)
|
49
|
-
rack (1.
|
50
|
-
rack-cache (1.2)
|
51
|
-
rack (>= 0.4)
|
63
|
+
rack (1.5.2)
|
52
64
|
rack-test (0.6.2)
|
53
65
|
rack (>= 1.0)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
rails (4.0.0)
|
67
|
+
actionmailer (= 4.0.0)
|
68
|
+
actionpack (= 4.0.0)
|
69
|
+
activerecord (= 4.0.0)
|
70
|
+
activesupport (= 4.0.0)
|
71
|
+
bundler (>= 1.3.0, < 2.0)
|
72
|
+
railties (= 4.0.0)
|
73
|
+
sprockets-rails (~> 2.0.0)
|
74
|
+
railties (4.0.0)
|
75
|
+
actionpack (= 4.0.0)
|
76
|
+
activesupport (= 4.0.0)
|
77
|
+
rake (>= 0.8.7)
|
78
|
+
thor (>= 0.18.1, < 2.0)
|
79
|
+
rake (10.1.0)
|
80
|
+
slop (3.4.5)
|
81
|
+
sprockets (2.10.0)
|
59
82
|
hike (~> 1.2)
|
60
83
|
multi_json (~> 1.0)
|
61
84
|
rack (~> 1.0)
|
62
85
|
tilt (~> 1.1, != 1.3.0)
|
63
|
-
|
86
|
+
sprockets-rails (2.0.0)
|
87
|
+
actionpack (>= 3.0)
|
88
|
+
activesupport (>= 3.0)
|
89
|
+
sprockets (~> 2.8)
|
90
|
+
thor (0.18.1)
|
91
|
+
thread_safe (0.1.0)
|
92
|
+
atomic
|
93
|
+
tilt (1.4.1)
|
94
|
+
treetop (1.4.14)
|
95
|
+
polyglot
|
96
|
+
polyglot (>= 0.3.1)
|
97
|
+
tzinfo (0.3.37)
|
64
98
|
|
65
99
|
PLATFORMS
|
66
100
|
ruby
|
67
101
|
|
68
102
|
DEPENDENCIES
|
69
|
-
actionpack
|
70
|
-
awesome_print
|
71
103
|
browser!
|
72
104
|
pry-meta
|
73
|
-
|
74
|
-
|
105
|
+
rack-test
|
106
|
+
rails
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Browser
|
2
|
+
|
3
|
+
[![Travis-CI](https://travis-ci.org/fnando/browser.png)](https://travis-ci.org/fnando/browser)
|
4
|
+
[![CodeClimate](https://codeclimate.com/github/fnando/browser.png)](https://codeclimate.com/github/fnando/browser)
|
5
|
+
|
6
|
+
Do some browser detection with Ruby. Includes ActionController integration.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```bash
|
11
|
+
gem install browser
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require "rubygems"
|
18
|
+
require "browser"
|
19
|
+
|
20
|
+
browser = Browser.new(:ua => "some string", :accept_language => "en-us")
|
21
|
+
browser.name # readable browser name
|
22
|
+
browser.safari?
|
23
|
+
browser.opera?
|
24
|
+
browser.chrome?
|
25
|
+
browser.mobile?
|
26
|
+
browser.tablet?
|
27
|
+
browser.firefox?
|
28
|
+
browser.ie?
|
29
|
+
browser.ie6? # this goes up to 10
|
30
|
+
browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
|
31
|
+
browser.platform # return :mac, :windows, :linux or :other
|
32
|
+
browser.mac?
|
33
|
+
browser.windows?
|
34
|
+
browser.linux?
|
35
|
+
browser.blackberry?
|
36
|
+
browser.meta # an array with several attributes
|
37
|
+
browser.to_s # the meta info joined by space
|
38
|
+
```
|
39
|
+
|
40
|
+
See the [tests](https://github.com/fnando/browser/blob/master/test/browser_test.rb) and [implementation](https://github.com/fnando/browser/blob/master/lib/browser.rb) for more examples.
|
41
|
+
|
42
|
+
### Rails integration
|
43
|
+
|
44
|
+
Just add it to the Gemfile.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
gem "browser"
|
48
|
+
```
|
49
|
+
|
50
|
+
This adds a helper method called `browser`, that inspects your current user agent.
|
51
|
+
|
52
|
+
```erb
|
53
|
+
<% if browser.ie6? %>
|
54
|
+
<p class="disclaimer">You're running an older IE version. Please update it!</p>
|
55
|
+
<% end %>
|
56
|
+
```
|
57
|
+
|
58
|
+
### Middleware
|
59
|
+
|
60
|
+
You can use the `Browser::Middleware` to redirect user agents.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
use Browser::Middleware do
|
64
|
+
redirect_to "/upgrade" unless browser.modern?
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
If you're using Rails, you can use the route helper methods. Just add something like the following to a initializer file (`config/initializers/browser.rb`).
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Rails.configuration.middleware.use Browser::Middleware do
|
72
|
+
redirect_to upgrade_path unless browser.modern?
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
Notice that you can have multiple conditionals.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Rails.configuration.middleware.use Browser::Middleware do
|
80
|
+
redirect_to upgrade_path(browser: "oldie") if browser.ie? && !browser.modern?
|
81
|
+
redirect_to upgrade_path(browser: "oldfx") if browser.firefox? && !browser.modern?
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
## Maintainer
|
86
|
+
|
87
|
+
* Nando Vieira - http://nandovieira.com.br
|
88
|
+
|
89
|
+
## Contributors
|
90
|
+
|
91
|
+
* https://github.com/fnando/browser/contributors
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
(The MIT License)
|
96
|
+
|
97
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
98
|
+
a copy of this software and associated documentation files (the
|
99
|
+
'Software'), to deal in the Software without restriction, including
|
100
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
101
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
102
|
+
permit persons to whom the Software is furnished to do so, subject to
|
103
|
+
the following conditions:
|
104
|
+
|
105
|
+
The above copyright notice and this permission notice shall be
|
106
|
+
included in all copies or substantial portions of the Software.
|
107
|
+
|
108
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
109
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
110
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
111
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
112
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
113
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
114
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require "bundler"
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
require "./lib/browser/version"
|
5
|
-
|
6
4
|
require "rake/testtask"
|
7
5
|
Rake::TestTask.new do |t|
|
8
6
|
t.libs << "lib"
|
@@ -12,13 +10,17 @@ Rake::TestTask.new do |t|
|
|
12
10
|
t.ruby_opts = %w[-rubygems]
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
desc "Run specs against all gemfiles"
|
14
|
+
task "test:all" do
|
15
|
+
%w[
|
16
|
+
Gemfile
|
17
|
+
gemfiles/rails3.gemfile
|
18
|
+
].each do |gemfile|
|
19
|
+
ENV["BUNDLE_GEMFILE"] = gemfile
|
20
|
+
puts "=> Running with Gemfile: #{gemfile}"
|
21
|
+
Rake::Task["test"].reenable
|
22
|
+
Rake::Task["test"].invoke
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
|
-
task :default =>
|
26
|
+
task :default => "test"
|
data/browser.gemspec
CHANGED
@@ -17,9 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_development_dependency "actionpack"
|
21
|
-
s.add_development_dependency "rake"
|
22
|
-
s.add_development_dependency "rdoc"
|
23
20
|
s.add_development_dependency "pry-meta"
|
24
|
-
s.add_development_dependency "
|
21
|
+
s.add_development_dependency "rails"
|
22
|
+
s.add_development_dependency "rack-test"
|
25
23
|
end
|
data/config.ru
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /mnt/hgfs/!%Projects/github/browser
|
3
|
+
specs:
|
4
|
+
browser (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionmailer (3.2.13)
|
10
|
+
actionpack (= 3.2.13)
|
11
|
+
mail (~> 2.5.3)
|
12
|
+
actionpack (3.2.13)
|
13
|
+
activemodel (= 3.2.13)
|
14
|
+
activesupport (= 3.2.13)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
journey (~> 1.0.4)
|
18
|
+
rack (~> 1.4.5)
|
19
|
+
rack-cache (~> 1.2)
|
20
|
+
rack-test (~> 0.6.1)
|
21
|
+
sprockets (~> 2.2.1)
|
22
|
+
activemodel (3.2.13)
|
23
|
+
activesupport (= 3.2.13)
|
24
|
+
builder (~> 3.0.0)
|
25
|
+
activerecord (3.2.13)
|
26
|
+
activemodel (= 3.2.13)
|
27
|
+
activesupport (= 3.2.13)
|
28
|
+
arel (~> 3.0.2)
|
29
|
+
tzinfo (~> 0.3.29)
|
30
|
+
activeresource (3.2.13)
|
31
|
+
activemodel (= 3.2.13)
|
32
|
+
activesupport (= 3.2.13)
|
33
|
+
activesupport (3.2.13)
|
34
|
+
i18n (= 0.6.1)
|
35
|
+
multi_json (~> 1.0)
|
36
|
+
arel (3.0.2)
|
37
|
+
awesome_print (1.1.0)
|
38
|
+
builder (3.0.4)
|
39
|
+
coderay (1.0.9)
|
40
|
+
erubis (2.7.0)
|
41
|
+
hike (1.2.3)
|
42
|
+
i18n (0.6.1)
|
43
|
+
journey (1.0.4)
|
44
|
+
json (1.8.0)
|
45
|
+
mail (2.5.4)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
method_source (0.8.1)
|
49
|
+
mime-types (1.23)
|
50
|
+
multi_json (1.7.7)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
pry (0.9.12.2)
|
53
|
+
coderay (~> 1.0.5)
|
54
|
+
method_source (~> 0.8)
|
55
|
+
slop (~> 3.4)
|
56
|
+
pry-meta (0.0.5)
|
57
|
+
awesome_print
|
58
|
+
pry
|
59
|
+
pry-nav
|
60
|
+
pry-remote
|
61
|
+
pry-nav (0.2.3)
|
62
|
+
pry (~> 0.9.10)
|
63
|
+
pry-remote (0.1.7)
|
64
|
+
pry (~> 0.9)
|
65
|
+
slop (~> 3.0)
|
66
|
+
rack (1.4.5)
|
67
|
+
rack-cache (1.2)
|
68
|
+
rack (>= 0.4)
|
69
|
+
rack-ssl (1.3.3)
|
70
|
+
rack
|
71
|
+
rack-test (0.6.2)
|
72
|
+
rack (>= 1.0)
|
73
|
+
rails (3.2.13)
|
74
|
+
actionmailer (= 3.2.13)
|
75
|
+
actionpack (= 3.2.13)
|
76
|
+
activerecord (= 3.2.13)
|
77
|
+
activeresource (= 3.2.13)
|
78
|
+
activesupport (= 3.2.13)
|
79
|
+
bundler (~> 1.0)
|
80
|
+
railties (= 3.2.13)
|
81
|
+
railties (3.2.13)
|
82
|
+
actionpack (= 3.2.13)
|
83
|
+
activesupport (= 3.2.13)
|
84
|
+
rack-ssl (~> 1.3.2)
|
85
|
+
rake (>= 0.8.7)
|
86
|
+
rdoc (~> 3.4)
|
87
|
+
thor (>= 0.14.6, < 2.0)
|
88
|
+
rake (10.1.0)
|
89
|
+
rdoc (3.12.2)
|
90
|
+
json (~> 1.4)
|
91
|
+
slop (3.4.5)
|
92
|
+
sprockets (2.2.2)
|
93
|
+
hike (~> 1.2)
|
94
|
+
multi_json (~> 1.0)
|
95
|
+
rack (~> 1.0)
|
96
|
+
tilt (~> 1.1, != 1.3.0)
|
97
|
+
thor (0.18.1)
|
98
|
+
tilt (1.4.1)
|
99
|
+
treetop (1.4.14)
|
100
|
+
polyglot
|
101
|
+
polyglot (>= 0.3.1)
|
102
|
+
tzinfo (0.3.37)
|
103
|
+
|
104
|
+
PLATFORMS
|
105
|
+
ruby
|
106
|
+
|
107
|
+
DEPENDENCIES
|
108
|
+
browser!
|
109
|
+
pry-meta
|
110
|
+
rack-test
|
111
|
+
rails (~> 3.2.13)
|