schmobile 0.1.0 → 0.1.1
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.
- data/README.rdoc +21 -14
- data/VERSION +1 -1
- data/lib/rack/schmobile/filters.rb +14 -0
- data/lib/rack/schmobile/request_extension.rb +1 -1
- data/lib/rack/schmobile.rb +0 -1
- data/schmobile.gemspec +1 -1
- data/test/test_rack_request.rb +2 -5
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
= schmobile
|
2
2
|
|
3
|
-
A mobile user agent detection Rack middleware.
|
3
|
+
A mobile user agent detection Rack middleware. It does this by providing +#is_mobile?+ to +Rack::Request+
|
4
|
+
|
5
|
+
== Forcing mobile mode
|
6
|
+
|
7
|
+
You can force toggle mobile mode by sending +is_mobile=true+ and +is_mobile=false+ as
|
8
|
+
parameters in the request URL. This setting will be stored in the session for subsequent requests.
|
9
|
+
This entirely overrides the user agent detection.
|
10
|
+
|
11
|
+
== User agent detection
|
12
|
+
|
13
|
+
You can add/remove user agents like so:
|
14
|
+
|
15
|
+
Rack::Schmobile::UserAgents.add_user_agent_pattern("wibble")
|
16
|
+
Rack::Schmobile::UserAgents.remove_user_agent_pattern("ipad")
|
17
|
+
|
18
|
+
== Filters
|
19
|
+
|
20
|
+
The outcome of the +request.is_mobile?+ call is the product of a series of filters getting evaluated
|
21
|
+
against the request. You can manipulate the Rack::Schmobile::Filters::CHAIN array to alter if a
|
22
|
+
request is deemed mobile or not. Add your own filter to bypass the check depending on e.g. location
|
23
|
+
or request format.
|
4
24
|
|
5
25
|
== Redirecting
|
6
26
|
|
@@ -16,23 +36,10 @@ Finally the middleware provides a request level method to determine if the clien
|
|
16
36
|
|
17
37
|
Rack::Request#is_mobile?
|
18
38
|
|
19
|
-
== Forcing mobile mode
|
20
|
-
|
21
|
-
You can force toggle mobile mode by sending +is_mobile=true+ and +is_mobile=false+ as
|
22
|
-
parameters in the request URL - note that these require session access. This entirely
|
23
|
-
overrides the user agent detection.
|
24
|
-
|
25
39
|
== Rolling out
|
26
40
|
|
27
41
|
use Rack::Schmobile, :redirect_to => "/mobile", :if => Proc.new { |request| request.host =~ /staging/ }
|
28
42
|
|
29
|
-
== User agent detection
|
30
|
-
|
31
|
-
You can add/remove user agents like so:
|
32
|
-
|
33
|
-
Rack::Schmobile::UserAgents.add_user_agent_pattern("wibble")
|
34
|
-
Rack::Schmobile::UserAgents.remove_user_agent_pattern("ipad")
|
35
|
-
|
36
43
|
== Thanks
|
37
44
|
|
38
45
|
Not quite what we were looking for, but good inspiration and may work for you:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -1,2 +1,16 @@
|
|
1
1
|
require 'rack/schmobile/filters/is_mobile_param'
|
2
2
|
require 'rack/schmobile/filters/mobile_user_agent'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
module Schmobile
|
6
|
+
# Filters are tests that get run against a request to detrmine if it's a mobile request or not.
|
7
|
+
# A filter can return true, false or nil. The first non-nil value of the filter chain is the
|
8
|
+
# one that gets used.
|
9
|
+
#
|
10
|
+
# You can modify the chain to add new conditions that check on e.g. request format.
|
11
|
+
module Filters
|
12
|
+
CHAIN = [ Rack::Schmobile::Filters::IsMobileParam, Rack::Schmobile::Filters::MobileUserAgent ]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/lib/rack/schmobile.rb
CHANGED
data/schmobile.gemspec
CHANGED
data/test/test_rack_request.rb
CHANGED
@@ -21,17 +21,14 @@ class TestRackRequest < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
should "return true for a mobile browser" do
|
25
|
-
assert request("HTTP_USER_AGENT" => iphone).is_mobile?
|
26
|
-
end
|
27
|
-
|
28
24
|
should "return false when forced in the session" do
|
29
25
|
Rack::Request.any_instance.stubs(:session).returns({ Rack::Schmobile::IS_MOBILE => false })
|
30
26
|
assert !request("HTTP_USER_AGENT" => iphone).is_mobile?
|
31
27
|
end
|
32
28
|
|
33
29
|
should "return true when forced in the session" do
|
34
|
-
|
30
|
+
Rack::Request.any_instance.stubs(:session).returns({ Rack::Schmobile::IS_MOBILE => true })
|
31
|
+
assert request.is_mobile?
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schmobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|