rack-mobile-detect 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,6 @@
1
+ ### 0.4.0: Jun 7, 2012 ###
2
+ * Added iPad as a targeted device, thank you sansari (https://github.com/sansari)
3
+
1
4
  ### 0.3.0: Mar 12, 2011 ###
2
5
  * Modified catch-all based: https://github.com/brendanlim/mobile-fu
3
6
 
data/README.md CHANGED
@@ -23,10 +23,10 @@ advanced capabilities - for example and iPhone or Android phone.
23
23
  Targeted mobile devices are detected via a `Regexp` applied against
24
24
  the HTTP User-Agent header.
25
25
 
26
- By default, the targeted devices are iPhone, Android and iPod. If a
27
- targeted device is detected, the token match from the regular
28
- expression will be the value passed in the `X_MOBILE_DEVICE` header,
29
- i.e.: `X_MOBILE_DEVICE: iPhone`
26
+ By default, the targeted devices are iPhone, iPad, Android and
27
+ iPod. If a targeted device is detected, the token match from the
28
+ regular expression will be the value passed in the `X_MOBILE_DEVICE`
29
+ header, i.e.: `X_MOBILE_DEVICE: iPhone`
30
30
 
31
31
 
32
32
  ### UAProf Detection ###
@@ -84,27 +84,29 @@ list you choose.
84
84
  Redirects
85
85
  =========
86
86
 
87
- use Rack::MobileDetect, :redirect_to => '/mobile'
87
+ use Rack::MobileDetect, :redirect_to => 'http://m.example.com/'
88
88
 
89
89
  This allows you to choose a custom redirect path any time a mobile
90
90
  device is detected.
91
91
 
92
92
  use Rack::MobileDetect, :targeted => /BlackBerry|iPhone/,
93
- :redirect_map => { 'BlackBerry' => '/m/blackberry', 'iPhone' => '/m/iphone' }
93
+ :redirect_map => { 'BlackBerry' => 'http://m.example.com/blackberry',
94
+ 'iPhone' => 'http://m.example.com/iphone' }
94
95
 
95
96
  This allows you to map specific redirect URLs to targeted devices. The
96
97
  key in the redirect_map should be the value of the matched pattern.
97
98
 
98
99
  use Rack::MobileDetect, :targeted => /BlackBerry|iPhone/,
99
- :redirect_map => { 'BlackBerry' => '/m/blackberry', 'iPhone' => '/m/iphone' },
100
- :redirect_to => '/mobile'
100
+ :redirect_map => { 'BlackBerry' => 'http://m.example.com/blackberry',
101
+ 'iPhone' => 'http://m.example.com/iphone' },
102
+ :redirect_to => 'http://m.example.com/'
101
103
 
102
104
  This allows you to map targeted devices to specific URLs. Non-targeted
103
105
  mobile devices will redirect to the url specified by redirect_to.
104
106
 
105
107
  In the example above, BlackBerrys and iPhones get redirected to
106
108
  device-specific URLs. All other mobile devices get redirected to
107
- '/mobile'.
109
+ 'http://m.example.com'.
108
110
 
109
111
 
110
112
  Utils
@@ -1,5 +1,5 @@
1
1
  ---
2
+ :patch: 0
2
3
  :major: 0
3
4
  :build:
4
- :minor: 3
5
- :patch: 0
5
+ :minor: 4
@@ -33,11 +33,11 @@ module Rack
33
33
  #
34
34
  # 1. Search for a 'targeted' mobile device. A targeted mobile device
35
35
  # is a mobile device you may want to provide special content to
36
- # because it has advanced capabilities - for example and iPhone or
36
+ # because it has advanced capabilities - for example an iPad, iPhone or
37
37
  # Android device. Targeted mobile devices are detected via a Regexp
38
38
  # applied against the HTTP User-Agent header.
39
39
  #
40
- # By default, the targeted devices are iPhone, Android and iPod. If
40
+ # By default, the targeted devices are iPhone, Android, iPad and iPod. If
41
41
  # a targeted device is detected, the token match from the regular
42
42
  # expression will be the value passed in the X_MOBILE_DEVICE header,
43
43
  # i.e.: X_MOBILE_DEVICE: iPhone
@@ -109,7 +109,7 @@ module Rack
109
109
  # captured. Captured tokens are passed through in the
110
110
  # environment variable. These are special mobile devices that
111
111
  # may have special rendering capabilities for you to target.
112
- @regex_ua_targeted = options[:targeted] || /iphone|android|ipod/i
112
+ @regex_ua_targeted = options[:targeted] || /iphone|android|ipod|ipad/i
113
113
 
114
114
  # Match mobile content in Accept header:
115
115
  # http://www.developershome.com/wap/detection/detection.asp?page=httpHeaders
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-mobile-detect}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Alison"]
12
- s.date = %q{2011-03-12}
12
+ s.date = %q{2012-06-07}
13
13
  s.description = %q{Rack::MobileDetect detects mobile devices and adds an
14
14
  X_MOBILE_DEVICE header to the request if a mobile device is detected. Specific
15
15
  devices can be targeted with custom Regexps and redirect support is available.}
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  ]
36
36
  s.homepage = %q{http://github.com/talison/rack-mobile-detect}
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.6.2}
38
+ s.rubygems_version = %q{1.3.6}
39
39
  s.summary = %q{Rack middleware for ruby webapps to detect mobile devices.}
40
40
  s.test_files = [
41
41
  "test/helper.rb",
@@ -43,9 +43,10 @@ Gem::Specification.new do |s|
43
43
  ]
44
44
 
45
45
  if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
47
  s.specification_version = 3
47
48
 
48
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
50
  s.add_development_dependency(%q<shoulda>, [">= 0"])
50
51
  s.add_runtime_dependency(%q<rack>, [">= 0"])
51
52
  else
@@ -26,6 +26,10 @@ class TestRackMobileDetect < Test::Unit::TestCase
26
26
  env = test_env({ 'HTTP_USER_AGENT' => android })
27
27
  @rack.call(env)
28
28
  assert_equal 'Android', env[x_mobile]
29
+
30
+ env = test_env({ 'HTTP_USER_AGENT' => ipad })
31
+ @rack.call(env)
32
+ assert_equal 'iPad', env[x_mobile]
29
33
  end
30
34
 
31
35
  should "detect UAProf device" do
@@ -130,7 +134,8 @@ class TestRackMobileDetect < Test::Unit::TestCase
130
134
  setup do
131
135
  @app = test_app
132
136
  # Custom redirect
133
- @rack = Rack::MobileDetect.new(@app, :redirect_to => '/mobile')
137
+ @rack = Rack::MobileDetect.new(@app,
138
+ :redirect_to => 'http://m.example.com/')
134
139
  end
135
140
 
136
141
  should "redirect to mobile website" do
@@ -139,14 +144,17 @@ class TestRackMobileDetect < Test::Unit::TestCase
139
144
  assert_equal 'iPhone', env[x_mobile]
140
145
 
141
146
  assert_equal(301, status)
142
- assert_equal({'Location' => "/mobile"}, headers)
147
+ assert_equal({'Location' => "http://m.example.com/"}, headers)
143
148
  end
144
149
  end
145
150
 
146
151
  context "An app with a custom redirect map" do
147
152
  setup do
148
153
  @app = test_app
149
- redirects = { "myphone" => "/m/myphone", "yourphone" => "/m/yourphone" }
154
+ redirects = {
155
+ "myphone" => "http://m.example.com/myphone",
156
+ "yourphone" => "http://m.example.com/yourphone"
157
+ }
150
158
  # Target fake devices
151
159
  @rack = Rack::MobileDetect.new(@app,
152
160
  :targeted => /myphone|yourphone/,
@@ -159,7 +167,7 @@ class TestRackMobileDetect < Test::Unit::TestCase
159
167
  assert_equal 'myphone', env[x_mobile]
160
168
 
161
169
  assert_equal(301, status)
162
- assert_equal({'Location' => "/m/myphone"}, headers)
170
+ assert_equal({'Location' => "http://m.example.com/myphone"}, headers)
163
171
 
164
172
 
165
173
  env = test_env({ 'HTTP_USER_AGENT' => 'yourphone sucks' })
@@ -167,7 +175,7 @@ class TestRackMobileDetect < Test::Unit::TestCase
167
175
  assert_equal 'yourphone', env[x_mobile]
168
176
 
169
177
  assert_equal(301, status)
170
- assert_equal({'Location' => "/m/yourphone"}, headers)
178
+ assert_equal({'Location' => "http://m.example.com/yourphone"}, headers)
171
179
 
172
180
  end
173
181
 
@@ -183,12 +191,15 @@ class TestRackMobileDetect < Test::Unit::TestCase
183
191
  context "An app with a custom redirect map and redirect_to option" do
184
192
  setup do
185
193
  @app = test_app
186
- redirects = { "myphone" => "/m/myphone", "yourphone" => "/m/yourphone" }
194
+ redirects = {
195
+ "myphone" => "http://m.example.com/myphone",
196
+ "yourphone" => "http://m.example.com/yourphone"
197
+ }
187
198
  # Target fake devices
188
199
  @rack = Rack::MobileDetect.new(@app,
189
200
  :targeted => /myphone|yourphone/,
190
201
  :redirect_map => redirects,
191
- :redirect_to => '/m/genericdevice')
202
+ :redirect_to => 'http://m.example.com/genericdevice')
192
203
  end
193
204
 
194
205
  should "use the redirect value in the redirect map when targeted" do
@@ -197,7 +208,7 @@ class TestRackMobileDetect < Test::Unit::TestCase
197
208
  assert_equal 'myphone', env[x_mobile]
198
209
 
199
210
  assert_equal(301, status)
200
- assert_equal({'Location' => "/m/myphone"}, headers)
211
+ assert_equal({'Location' => "http://m.example.com/myphone"}, headers)
201
212
 
202
213
  end
203
214
 
@@ -207,8 +218,9 @@ class TestRackMobileDetect < Test::Unit::TestCase
207
218
  assert_equal 'true', env[x_mobile]
208
219
 
209
220
  assert_equal(301, status)
210
- assert_equal({'Location' => "/m/genericdevice"}, headers)
221
+ assert_equal({'Location' => "http://m.example.com/genericdevice"}, headers)
211
222
  end
223
+
212
224
  end
213
225
 
214
226
 
@@ -218,6 +230,9 @@ class TestRackMobileDetect < Test::Unit::TestCase
218
230
  end
219
231
 
220
232
  # User agents for testing
233
+ def ipad
234
+ 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10'
235
+ end
221
236
  def ipod
222
237
  'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5G77 Safari/525.20'
223
238
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mobile-detect
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 3
7
+ - 4
9
8
  - 0
10
- version: 0.3.0
9
+ version: 0.4.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Tom Alison
@@ -15,18 +14,16 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-03-12 00:00:00 -08:00
17
+ date: 2012-06-07 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: shoulda
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 3
30
27
  segments:
31
28
  - 0
32
29
  version: "0"
@@ -36,11 +33,9 @@ dependencies:
36
33
  name: rack
37
34
  prerelease: false
38
35
  requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
37
  - - ">="
42
38
  - !ruby/object:Gem::Version
43
- hash: 3
44
39
  segments:
45
40
  - 0
46
41
  version: "0"
@@ -82,27 +77,23 @@ rdoc_options: []
82
77
  require_paths:
83
78
  - lib
84
79
  required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
80
  requirements:
87
81
  - - ">="
88
82
  - !ruby/object:Gem::Version
89
- hash: 3
90
83
  segments:
91
84
  - 0
92
85
  version: "0"
93
86
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
87
  requirements:
96
88
  - - ">="
97
89
  - !ruby/object:Gem::Version
98
- hash: 3
99
90
  segments:
100
91
  - 0
101
92
  version: "0"
102
93
  requirements: []
103
94
 
104
95
  rubyforge_project:
105
- rubygems_version: 1.6.2
96
+ rubygems_version: 1.3.6
106
97
  signing_key:
107
98
  specification_version: 3
108
99
  summary: Rack middleware for ruby webapps to detect mobile devices.