contentfree-is_it_mobile 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/is_it_mobile.gemspec +3 -3
- data/lib/is_it_mobile.rb +28 -33
- data/lib/rails/init.rb +3 -3
- metadata +2 -2
data/VERSION.yml
CHANGED
data/is_it_mobile.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{is_it_mobile}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Dave Myron"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-13}
|
10
10
|
s.description = %q{TODO}
|
11
11
|
s.email = %q{dave.myron@contentfree.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.homepage = %q{http://github.com/contentfree/is_it_mobile}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
34
|
+
s.rubygems_version = %q{1.3.4}
|
35
35
|
s.summary = %q{TODO}
|
36
36
|
s.test_files = [
|
37
37
|
"spec/is_it_mobile_spec.rb",
|
data/lib/is_it_mobile.rb
CHANGED
@@ -1,42 +1,37 @@
|
|
1
1
|
class IsItMobile
|
2
|
-
|
3
|
-
w3c acs- alav alca amoi audi avan benq bird blac blaz
|
4
|
-
brew cell cldc cmd- dang doco eric hipt inno ipaq java
|
5
|
-
jigs kddi keji leno lg-c lg-d lg-g lge- maui maxo midp
|
6
|
-
mits mmef mobi mot- moto mwbp nec- newt noki oper palm
|
7
|
-
pana pant phil play port prox qwap sage sams sany sch-
|
8
|
-
sec- send seri sgh- shar sie- siem smal smar sony sph-
|
9
|
-
symb t-mo teli tim- tosh tsm- upg1 upsi vk-v voda wap-
|
10
|
-
wapa wapi wapp wapr webc webo winw winw xda xda-
|
11
|
-
).join('|')})/i
|
2
|
+
MOBILE_USER_AGENT_FRAGMENTS = %r{^(1207|3gso|4thp|501i|502i|503i|504i|505i|506i|6310|6590|770s|802s|a wa|acer|acs-|airn|alav|asus|attw|au-m|aur |aus |abac|acoo|aiko|alco|alca|amoi|anex|anny|anyw|aptu|arch|argo|bell|bird|bw-n|bw-u|beck|benq|bilb|blac|c55/|cdm-|chtm|capi|comp|cond|craw|dall|dbte|dc-s|dica|ds-d|ds12|dait|devi|dmob|doco|dopo|el49|erk0|esl8|ez40|ez60|ez70|ezos|ezze|elai|emul|eric|ezwa|fake|fly-|fly_|g-mo|g1 u|g560|gf-5|grun|gene|go.w|good|grad|hcit|hd-m|hd-p|hd-t|hei-|hp i|hpip|hs-c|htc |htc-|htca|htcg|htcp|htcs|htct|htc_|haie|hita|huaw|hutc|i-20|i-go|i-ma|i230|iac|iac-|iac/|ig01|im1k|inno|iris|jata|java|kddi|kgt|kgt/|kpt |kwc-|klon|lexi|lg g|lg-a|lg-b|lg-c|lg-d|lg-f|lg-g|lg-k|lg-l|lg-m|lg-o|lg-p|lg-s|lg-t|lg-u|lg-w|lg/k|lg/l|lg/u|lg50|lg54|lge-|lge/|lynx|leno|m1-w|m3ga|m50/|maui|mc01|mc21|mcca|medi|meri|mio8|mioa|mo01|mo02|mode|modo|mot |mot-|mt50|mtp1|mtv |mate|maxo|merc|mits|mobi|motv|mozz|n100|n101|n102|n202|n203|n300|n302|n500|n502|n505|n700|n701|n710|nec-|nem-|newg|neon|netf|noki|nzph|o2 x|o2-x|opwv|owg1|opti|oran|p800|pand|pg-1|pg-2|pg-3|pg-6|pg-8|pg-c|pg13|phil|pn-2|pt-g|palm|pana|pire|pock|pose|psio|qa-a|qc-2|qc-3|qc-5|qc-7|qc07|qc12|qc21|qc32|qc60|qci-|qwap|qtek|r380|r600|raks|rim9|rove|s55/|sage|sams|sc01|sch-|scp-|sdk/|se47|sec-|sec0|sec1|semc|sgh-|shar|sie-|sk-0|sl45|slid|smb3|smt5|sp01|sph-|spv |spv-|sy01|samm|sany|sava|scoo|send|siem|smar|smit|soft|sony|t-mo|t218|t250|t600|t610|t618|tcl-|tdg-|telm|tim-|ts70|tsm-|tsm3|tsm5|tx-9|tagt|talk|teli|topl|tosh|up.b|upg1|utst|v400|v750|veri|vk-v|vk40|vk50|vk52|vk53|vm40|vx98|virg|vite|voda|vulc|w3c |w3c-|wapj|wapp|wapu|wapm|wig |wapi|wapr|wapv|wapy|wapa|waps|wapt|winc|winw|wonu|x700|xda2|xdag|yas-|your|zte-|zeto|acs-|alav|alca|amoi|aste|audi|avan|benq|bird|blac|blaz|brew|brvw|bumb|ccwa|cell|cldc|cmd-|dang|doco|eml2|eric|fetc|hipt|http|ibro|idea|ikom|inno|ipaq|jbro|jemu|java|jigs|kddi|keji|kyoc|kyok|leno|lg-c|lg-d|lg-g|lge-|libw|m-cr|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|mywa|nec-|newt|nok6|noki|o2im|opwv|palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|rozo|sage|sama|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|treo|tsm-|upg1|upsi|vk-v|voda|vx52|vx53|vx60|vx61|vx70|vx80|vx81|vx83|vx85|wap-|wapa|wapi|wapp|wapr|webc|whit|winw|wmlb|xda-)}i
|
12
3
|
|
13
|
-
|
4
|
+
MOBILE_USER_AGENTS = {
|
5
|
+
:iphone => 'i(phone|pod)',
|
6
|
+
:android => 'android',
|
7
|
+
:opera_mini => 'opera mini',
|
8
|
+
:blackberry => 'blackberry',
|
9
|
+
:palm => 'palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine',
|
10
|
+
:zune => 'zune',
|
11
|
+
:windows_mobile => 'windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile',
|
12
|
+
:symbian => 'symbian',
|
13
|
+
:wii => 'wii',
|
14
|
+
:playstation => 'playstation',
|
15
|
+
:other => 'up.browser|up.link|mmp|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo'
|
16
|
+
}
|
17
|
+
POPULAR_MOBILE_USER_AGENT_REGEX = %r{(#{MOBILE_USER_AGENTS.collect{|category,regex| regex}.join('|')})}i
|
18
|
+
POPULAR_DEVICES = MOBILE_USER_AGENTS.keys.reject{ |key| key == :other }
|
19
|
+
|
20
|
+
MOBILE_ACCEPTS_HEADERS = %r{(text/vnd\.wap\.wml|application/vnd\.wap\.xhtml\+xml)}i
|
14
21
|
|
15
22
|
# Performs a few lightweight checks on the user agent to determine if it's a mobile device.
|
16
23
|
def self.mobile?( user_agent, accepts = '' )
|
17
|
-
!!( user_agent =~ POPULAR_MOBILE_USER_AGENT_REGEX ||
|
18
|
-
accepts.
|
19
|
-
user_agent =~
|
20
|
-
end
|
21
|
-
|
22
|
-
# Some checks for some specific, popular mobile devices
|
23
|
-
def self.iphone?( user_agent )
|
24
|
-
!!(user_agent =~ /(mobile\/.+safari)/i)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.android?( user_agent )
|
28
|
-
!!(user_agent =~ /android/i)
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.blackberry?( user_agent )
|
32
|
-
!!(user_agent =~ /blackberry/i)
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.windows_mobile?( user_agent )
|
36
|
-
!!(user_agent =~ /windows ce/i)
|
24
|
+
!!( user_agent.to_s =~ POPULAR_MOBILE_USER_AGENT_REGEX ||
|
25
|
+
accepts.to_s =~ MOBILE_ACCEPTS_HEADERS ||
|
26
|
+
user_agent.to_s =~ MOBILE_USER_AGENT_FRAGMENTS )
|
37
27
|
end
|
38
28
|
|
39
|
-
|
40
|
-
|
29
|
+
# Create some methods to check for some popular mobile device types
|
30
|
+
POPULAR_DEVICES.each do |type|
|
31
|
+
class_eval <<-EOE
|
32
|
+
def self.#{type}?( user_agent )
|
33
|
+
!!(user_agent =~ %r{\#{MOBILE_USER_AGENTS[:#{type}]}}i)
|
34
|
+
end
|
35
|
+
EOE
|
41
36
|
end
|
42
37
|
end
|
data/lib/rails/init.rb
CHANGED
@@ -22,7 +22,7 @@ module IsItMobile::ForRails
|
|
22
22
|
before_filter :change_request_format_to_mobile, :if => :request_is_from_mobile?
|
23
23
|
|
24
24
|
helper_method :request_is_from_mobile?, :mobile?
|
25
|
-
|
25
|
+
IsItMobile::POPULAR_DEVICES.each do |device|
|
26
26
|
helper_method "request_is_from_#{device}?".to_sym, "#{device}?".to_sym
|
27
27
|
end
|
28
28
|
end
|
@@ -37,7 +37,7 @@ module IsItMobile::ForRails
|
|
37
37
|
def request_is_from_mobile?
|
38
38
|
@request_is_from_mobile ||=
|
39
39
|
request.format.to_sym == self.class.mobile_format ||
|
40
|
-
IsItMobile.mobile?( request.env['HTTP_USER_AGENT']
|
40
|
+
IsItMobile.mobile?( request.env['HTTP_USER_AGENT'].to_s, request.env['HTTP_ACCEPT'].to_s )
|
41
41
|
end
|
42
42
|
alias :mobile? :request_is_from_mobile?
|
43
43
|
|
@@ -49,7 +49,7 @@ module IsItMobile::ForRails
|
|
49
49
|
# Some helpers for popular devices - these don't (yet) wrangle the request format
|
50
50
|
# This will create methods named "request_is_from_(device)?" which are also aliased to
|
51
51
|
# just "(device)?"
|
52
|
-
|
52
|
+
IsItMobile::POPULAR_DEVICES.each do |device|
|
53
53
|
module_eval <<-EOD
|
54
54
|
def request_is_from_#{device}?
|
55
55
|
@request_is_from_#{device} ||= IsItMobile.#{device}?( request.env['HTTP_USER_AGENT'] )
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentfree-is_it_mobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Myron
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-13 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|