mobylette 3.2 → 3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,6 +76,14 @@ Mobylette works uppon detecting the user agent of the visitor browser. By defaul
76
76
  config[:mobile_user_agents] = proc { %r{iphone|ipad}i }
77
77
  end
78
78
 
79
+ === Skipping User Agents
80
+
81
+ If you need to exclude one or more user agents from the mobile format, lets say ipad for example, you may use the :skip_user_agents option:
82
+
83
+ mobylette_config do |config|
84
+ config[:skip_user_agents] = [:ipad]
85
+ end
86
+
79
87
  === Fall Backs
80
88
 
81
89
  Fall backs are handled as a chain of formats. By default the only chain is `:mobile => [:mobile, :html]`.
@@ -41,6 +41,7 @@ module Mobylette
41
41
  @@mobylette_options[:fallback_chains] = { mobile: [:mobile, :html] }
42
42
  @@mobylette_options[:mobile_user_agents] = Mobylette::MobileUserAgents.new
43
43
  @@mobylette_options[:devices] = Hash.new
44
+ @@mobylette_options[:skip_user_agents] = []
44
45
 
45
46
  cattr_accessor :mobylette_resolver
46
47
  self.mobylette_resolver = Mobylette::Resolvers::ChainedFallbackResolver.new({}, self.view_paths)
@@ -73,6 +74,8 @@ module Mobylette
73
74
  # Once a device is registered you may call the helper request_device?(device_symb)
74
75
  # to see if the request comes from that device or not.
75
76
  # By default :iphone, :ipad, :ios and :android are already registered.
77
+ # * skip_user_agents: [:ipad, :android]
78
+ # Don't consider these user agents mobile devices.
76
79
  #
77
80
  # Example Usage:
78
81
  #
@@ -151,7 +154,15 @@ module Mobylette
151
154
  #
152
155
  def respond_as_mobile?
153
156
  impediments = stop_processing_because_xhr? || stop_processing_because_param?
154
- (not impediments) && (force_mobile_by_session? || is_mobile_request? || params[:format] == 'mobile')
157
+ (not impediments) && (force_mobile_by_session? || allow_mobile_response? || params[:format] == 'mobile')
158
+ end
159
+
160
+ def allow_mobile_response?
161
+ user_agent_included? && is_mobile_request?
162
+ end
163
+
164
+ def user_agent_included?
165
+ request.user_agent.to_s.downcase !~ Regexp.union([self.mobylette_options[:skip_user_agents]].flatten.map(&:to_s))
155
166
  end
156
167
 
157
168
  # Private: Returns true if the visitor has the force_mobile set in it's session
@@ -1,3 +1,3 @@
1
1
  module Mobylette
2
- VERSION = "3.2"
2
+ VERSION = "3.3"
3
3
  end
@@ -27,3 +27,6 @@ DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any
27
27
  DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any more. See the README for :fallback_chains instead.
28
28
  DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any more. See the README for :fallback_chains instead.
29
29
  DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any more. See the README for :fallback_chains instead.
30
+ DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any more. See the README for :fallback_chains instead.
31
+ DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any more. See the README for :fallback_chains instead.
32
+ DEPRECATED > Mobylette: Please don't user :fall_back to configure fall backs any more. See the README for :fallback_chains instead.
@@ -164,6 +164,8 @@ module Mobylette
164
164
  subject.stub(:force_mobile_by_session?).and_return(false)
165
165
  subject.stub(:is_mobile_request?).and_return(false)
166
166
  subject.stub(:params).and_return({})
167
+ request = double("request", user_agent: "android")
168
+ subject.stub(:request).and_return(request)
167
169
  end
168
170
 
169
171
  it "should be true if force_mobile_by_session? is true" do
@@ -181,6 +183,34 @@ module Mobylette
181
183
  subject.send(:respond_as_mobile?).should be_true
182
184
  end
183
185
  end
186
+
187
+ context "with skip_user_agents config option set" do
188
+ before(:each) do
189
+ subject.stub(:stop_processing_because_xhr?).and_return(false)
190
+ subject.stub(:stop_processing_because_param?).and_return(false)
191
+ subject.stub(:force_mobile_by_session?).and_return(false)
192
+ subject.stub(:is_mobile_request?).and_return(true)
193
+ subject.stub(:params).and_return({})
194
+ request = double("request", user_agent: "ipad")
195
+ subject.stub(:request).and_return(request)
196
+ end
197
+
198
+ it "should be false if skip_user_agents contains the current user agent" do
199
+ subject.mobylette_options[:skip_user_agents] = [:ipad, :android]
200
+ subject.send(:respond_as_mobile?).should be_false
201
+ end
202
+
203
+ it "should be true if skip_user_agents is not set" do
204
+ subject.mobylette_options[:skip_user_agents] = []
205
+ subject.send(:respond_as_mobile?).should be_true
206
+ end
207
+
208
+ it "should be true if skip_user_agents does not contain the current user agent" do
209
+ subject.mobylette_options[:skip_user_agents] = [:android]
210
+ subject.send(:respond_as_mobile?).should be_true
211
+ end
212
+
213
+ end
184
214
  end
185
215
 
186
216
  describe "#handle_mobile" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobylette
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.2'
4
+ version: '3.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-22 00:00:00.000000000 Z
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -177,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  segments:
179
179
  - 0
180
- hash: -3729222328630037007
180
+ hash: 846771552519936959
181
181
  required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: -3729222328630037007
189
+ hash: 846771552519936959
190
190
  requirements: []
191
191
  rubyforge_project:
192
192
  rubygems_version: 1.8.24