is_it_mobile 1.0.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.
- data.tar.gz.sig +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.txt +73 -0
- data/Rakefile +12 -0
- data/lib/is_it_mobile.rb +24 -0
- data/test/test_is_it_mobile.rb +1 -0
- metadata +91 -0
- metadata.gz.sig +2 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
= is_it_mobile
|
2
|
+
|
3
|
+
* http://rubyforge.org/projects/contentfree/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Simply determines if a user agent is for a mobile device.
|
8
|
+
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* Fast & Lightweight (doesn't use anything like WURFL, which would be overkill for a quick check)
|
13
|
+
* Comes with a module for Rails 2.0 to enable a custom mime type handler for mobile devices
|
14
|
+
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
The lightweight tests used in IsItMobile are almost completely based on the work of Andy Moore in an
|
19
|
+
article at http://www.andymoore.info/php-to-detect-mobile-phones/. I added a couple more
|
20
|
+
user agents to the mix and obviously Rubified it.
|
21
|
+
|
22
|
+
It recognizes 99% of the mobile user agents from http://www.zytrax.com/tech/web/mobile_ids.html
|
23
|
+
It has nearly no false positives using the user agents from http://www.zytrax.com/tech/web/browser_ids.htm
|
24
|
+
The ones that don't quite pass are very rare (and some are even questionable appearing in their respective lists)
|
25
|
+
|
26
|
+
With Rails 2.0, you can use its multiview capabilities by simply adding this to your app:
|
27
|
+
- in config/initializers/mime_types.rb
|
28
|
+
Mime::Type.register_alias "text/html", :mobile
|
29
|
+
|
30
|
+
- in app/controllers/application.rb
|
31
|
+
require 'is_it_mobile'
|
32
|
+
class ApplicationController < ActionController::Base
|
33
|
+
include IsItMobile::ForRails
|
34
|
+
end
|
35
|
+
|
36
|
+
Then, just create your views using suffices of mobile.erb instead of html.erb
|
37
|
+
|
38
|
+
You can also just use IsItMobile directly:
|
39
|
+
IsItMobile.mobile? 'NokiaN90-1/3.0545.5.1 Series60/2.8 Profile/MIDP-2.0 Configuration/CLDC-1.1' # => true
|
40
|
+
|
41
|
+
|
42
|
+
== REQUIREMENTS:
|
43
|
+
|
44
|
+
* None
|
45
|
+
|
46
|
+
|
47
|
+
== INSTALL:
|
48
|
+
|
49
|
+
* sudo gem install is_it_mobile
|
50
|
+
|
51
|
+
|
52
|
+
== LICENSE:
|
53
|
+
|
54
|
+
Copyright (c) 2008
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
57
|
+
a copy of this software and associated documentation files (the
|
58
|
+
'Software'), to deal in the Software without restriction, including
|
59
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
60
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
61
|
+
permit persons to whom the Software is furnished to do so, subject to
|
62
|
+
the following conditions:
|
63
|
+
|
64
|
+
The above copyright notice and this permission notice shall be
|
65
|
+
included in all copies or substantial portions of the Software.
|
66
|
+
|
67
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
68
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
69
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
70
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
71
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
72
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
73
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/is_it_mobile.rb'
|
6
|
+
|
7
|
+
Hoe.new('is_it_mobile', IsItMobile::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'contentfree'
|
9
|
+
p.developer('Dave Myron', 'dave.myron@contentfree.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
task :release_and_publish => [:release, :publish_docs]
|
data/lib/is_it_mobile.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class IsItMobile
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
|
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
|
+
|
6
|
+
module ForRails
|
7
|
+
def included?(base)
|
8
|
+
base.class_eval do
|
9
|
+
before_filter :wrangle_format_if_request_is_mobile
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def wrangle_format_if_request_is_mobile
|
14
|
+
request.format = :mobile if IsItMobile.mobile?( @env['HTTP_USER_AGENT'], @env['HTTP_ACCEPT'])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Check if the given user agent is for a mobile device.
|
19
|
+
def self.mobile?( user_agent, accepts = '' )
|
20
|
+
return !!( user_agent =~ /(mobile|up.browser|up.link|mmp|symbian|phone|midp|wap|mini|ppc;|playstation|palm|wii|nitro)/i ||
|
21
|
+
accepts.index('application/vnd.wap.xhtml+xml') ||
|
22
|
+
POPULAR_MOBILE_USER_AGENT_BEGINNINGS.include?(user_agent[0,4]))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# TODO: Tests!
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: is_it_mobile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Myron
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDQjCCAiqgAwIBAgIBADANBgkqhkiG9w0BAQUFADBHMRMwEQYDVQQDDApkYXZl
|
14
|
+
Lm15cm9uMRswGQYKCZImiZPyLGQBGRYLY29udGVudGZyZWUxEzARBgoJkiaJk/Is
|
15
|
+
ZAEZFgNjb20wHhcNMDgwNDE3MTAwNTMzWhcNMDkwNDE3MTAwNTMzWjBHMRMwEQYD
|
16
|
+
VQQDDApkYXZlLm15cm9uMRswGQYKCZImiZPyLGQBGRYLY29udGVudGZyZWUxEzAR
|
17
|
+
BgoJkiaJk/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
|
18
|
+
AQDS5jTexxypvZPqoIRWYcbNGbbgHMn5pd2dUA74fq5IJ0y0J9TK/xy2Ncf8Hv6l
|
19
|
+
o43531AmDVlPQ7aTTZfqDHQQEoCsHiTxtIc8S3mRQ03exGG+sJIq5Fsgzqg2jvQh
|
20
|
+
MF3lWjVgENU8/INxpW4f/iST/ojn/PciYSIKs6SBcm9tHfU/jiMOT0qxCkyVAxM0
|
21
|
+
0rD/yPQyPb7ogUNsO3RU1v5KBrlcV3lQPRQyRCDUpJ6H0AmeAa4iax/xfK0d/ta+
|
22
|
+
A9t4MmelIMUohH3VYEgYzCN/SnJsLMcEWbaXYFJMUUk07f+EmV060VUi4vsqvrMy
|
23
|
+
vyRmhHyxBuiyNNoSi/wfF3ebAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQD
|
24
|
+
AgSwMB0GA1UdDgQWBBSYmhWA9lg6R++f6Z0m5/ZJ8mwTAzANBgkqhkiG9w0BAQUF
|
25
|
+
AAOCAQEANprOIqYQsh0myh1GeHwTYo75bFHeMns5kkx44pVRSNWO4M5WEVFztyqO
|
26
|
+
VW8ZS4aHOqZ/XvOZ3YIP0mNNJEOM3jVirbdRBBnu75q87xDuPX0HVkk687qXFfJ7
|
27
|
+
Qb+KYshgOEn3n1iBzL6zIYyPOFRxFBEeix7uAZw9gq/EJf7isDToYKG+BE+q53ES
|
28
|
+
i/ul3Zg65QMGyXWBJlDEcQ7bxD/+pdUhOqew5tBuMvgxB/9XUPTCTLK9rfhakiBd
|
29
|
+
ZOWAbHDEFtZtQMT5GUHvuZ5jqfEKsE8tkFfFnUPY7DwpqWKkhuQzmmunB2J9aykn
|
30
|
+
arkBVHd8TABNoJ+MQvwL/7sCwSTiTg==
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2008-04-17 00:00:00 -07:00
|
34
|
+
default_executable:
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hoe
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.5.1
|
44
|
+
version:
|
45
|
+
description: Simply determines if a user agent is for a mobile device.
|
46
|
+
email:
|
47
|
+
- dave.myron@contentfree.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- History.txt
|
54
|
+
- Manifest.txt
|
55
|
+
- README.txt
|
56
|
+
files:
|
57
|
+
- History.txt
|
58
|
+
- Manifest.txt
|
59
|
+
- README.txt
|
60
|
+
- Rakefile
|
61
|
+
- lib/is_it_mobile.rb
|
62
|
+
- test/test_is_it_mobile.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://rubyforge.org/projects/contentfree/
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --main
|
68
|
+
- README.txt
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project: contentfree
|
86
|
+
rubygems_version: 1.1.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 2
|
89
|
+
summary: Simply determines if a user agent is for a mobile device.
|
90
|
+
test_files:
|
91
|
+
- test/test_is_it_mobile.rb
|
metadata.gz.sig
ADDED