is_it_mobile 1.0.0.3 → 1.0.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.tar.gz.sig +0 -0
- data/README.txt +2 -3
- data/lib/is_it_mobile.rb +29 -10
- metadata +1 -1
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/README.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
= is_it_mobile
|
2
|
-
|
3
2
|
* http://rubyforge.org/projects/contentfree/
|
4
3
|
|
5
4
|
== DESCRIPTION:
|
@@ -42,12 +41,12 @@ IsItMobile.mobile? 'NokiaN90-1/3.0545.5.1 Series60/2.8 Profile/MIDP-2.0 Configur
|
|
42
41
|
|
43
42
|
== REQUIREMENTS:
|
44
43
|
|
45
|
-
|
44
|
+
None
|
46
45
|
|
47
46
|
|
48
47
|
== INSTALL:
|
49
48
|
|
50
|
-
|
49
|
+
sudo gem install is_it_mobile
|
51
50
|
|
52
51
|
|
53
52
|
== LICENSE:
|
data/lib/is_it_mobile.rb
CHANGED
@@ -1,25 +1,44 @@
|
|
1
1
|
class IsItMobile
|
2
|
-
VERSION = '1.0.
|
2
|
+
VERSION = '1.0.1'
|
3
3
|
|
4
4
|
POPULAR_MOBILE_USER_AGENT_BEGINNINGS = ['w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox', 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-']
|
5
|
-
|
5
|
+
|
6
|
+
# Performs a few lightweight checks on the user agent to determine if it's a mobile device.
|
7
|
+
def self.mobile?( user_agent, accepts )
|
8
|
+
return !!( user_agent =~ /(mobile|up.browser|up.link|mmp|symbian|phone|midp|wap|mini|ppc;|playstation|palm|wii|nitro)/i ||
|
9
|
+
accepts.index('application/vnd.wap.xhtml+xml') ||
|
10
|
+
POPULAR_MOBILE_USER_AGENT_BEGINNINGS.include?(user_agent[0,4]))
|
11
|
+
end
|
12
|
+
|
6
13
|
module ForRails
|
14
|
+
# When ForRails is included in a controller, a before filter is added that will reset the request format to the
|
15
|
+
# value of +base.mobile_format+ which defaults to :mobile. To change it to something else, simply add a line after
|
16
|
+
# the inclusion that says +self.mobile_format = :handheld+ or whatever you'd like it to be.
|
17
|
+
#
|
18
|
+
# It also exposes the +request_is_from_mobile?+ method to the views if you don't want to create multiple erb views
|
19
|
+
# for every page (or want to keep a single layout file)
|
7
20
|
def self.included(base)
|
8
21
|
base.class_eval do
|
22
|
+
class_inheritable_accessor :mobile_format
|
23
|
+
self.mobile_format = :mobile
|
24
|
+
|
9
25
|
before_filter :wrangle_format_if_request_is_mobile
|
26
|
+
|
27
|
+
helper_method :request_is_from_mobile?
|
10
28
|
end
|
11
29
|
end
|
12
30
|
|
13
31
|
protected
|
32
|
+
# Checks if the request.format is *already* @@mobile_format (set by the query string or using an
|
33
|
+
# extension of 'mobile' with resourceful routes) and if not, uses IsItMobile.mobile? to
|
34
|
+
# determine whether or not the request is from a mobile device
|
35
|
+
def request_is_from_mobile?
|
36
|
+
@request_is_from_mobile ||= request.format.to_sym == self.class.mobile_format || IsItMobile.mobile?( request.env['HTTP_USER_AGENT'] || '', request.env['HTTP_ACCEPT'] || '' )
|
37
|
+
end
|
38
|
+
|
39
|
+
# Sets the request format to @@mobile_format when the request is from a mobile device
|
14
40
|
def wrangle_format_if_request_is_mobile
|
15
|
-
request.format =
|
41
|
+
request.format = self.class.mobile_format if request_is_from_mobile?
|
16
42
|
end
|
17
43
|
end
|
18
|
-
|
19
|
-
# Check if the given user agent is for a mobile device.
|
20
|
-
def self.mobile?( user_agent, accepts )
|
21
|
-
return !!( user_agent =~ /(mobile|up.browser|up.link|mmp|symbian|phone|midp|wap|mini|ppc;|playstation|palm|wii|nitro)/i ||
|
22
|
-
accepts.index('application/vnd.wap.xhtml+xml') ||
|
23
|
-
POPULAR_MOBILE_USER_AGENT_BEGINNINGS.include?(user_agent[0,4]))
|
24
|
-
end
|
25
44
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|