Permalink
Browse files

Switch to using rack-mobile-detect

* Also tidy up a little
  • Loading branch information...
benlangfeld committed Apr 27, 2011
1 parent 062ef97 commit 377636246d179e5850957d7b1150181763041830
Showing with 19 additions and 98 deletions.
  1. +4 −0 .gitignore
  2. +0 −89 Gemfile.lock
  3. +14 −9 lib/mobile-fu.rb
  4. +1 −0 mobile-fu.gemspec
View
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
View
@@ -1,89 +0,0 @@
-PATH
- remote: .
- specs:
- mobile-fu (0.0.1)
- rails
-
-GEM
- remote: http://rubygems.org/
- specs:
- abstract (1.0.0)
- actionmailer (3.0.6)
- actionpack (= 3.0.6)
- mail (~> 2.2.15)
- actionpack (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
- builder (~> 2.1.2)
- erubis (~> 2.6.6)
- i18n (~> 0.5.0)
- rack (~> 1.2.1)
- rack-mount (~> 0.6.14)
- rack-test (~> 0.5.7)
- tzinfo (~> 0.3.23)
- activemodel (3.0.6)
- activesupport (= 3.0.6)
- builder (~> 2.1.2)
- i18n (~> 0.5.0)
- activerecord (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
- arel (~> 2.0.2)
- tzinfo (~> 0.3.23)
- activeresource (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
- activesupport (3.0.6)
- arel (2.0.9)
- builder (2.1.2)
- diff-lcs (1.1.2)
- erubis (2.6.6)
- abstract (>= 1.0.0)
- i18n (0.5.0)
- mail (2.2.15)
- activesupport (>= 2.3.6)
- i18n (>= 0.4.0)
- mime-types (~> 1.16)
- treetop (~> 1.4.8)
- mime-types (1.16)
- polyglot (0.3.1)
- rack (1.2.2)
- rack-mount (0.6.14)
- rack (>= 1.0.0)
- rack-test (0.5.7)
- rack (>= 1.0)
- rails (3.0.6)
- actionmailer (= 3.0.6)
- actionpack (= 3.0.6)
- activerecord (= 3.0.6)
- activeresource (= 3.0.6)
- activesupport (= 3.0.6)
- bundler (~> 1.0)
- railties (= 3.0.6)
- railties (3.0.6)
- actionpack (= 3.0.6)
- activesupport (= 3.0.6)
- rake (>= 0.8.7)
- thor (~> 0.14.4)
- rake (0.8.7)
- rdoc (3.5.3)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
- thor (0.14.6)
- treetop (1.4.9)
- polyglot (>= 0.3.1)
- tzinfo (0.3.26)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- mobile-fu!
- rdoc
- rspec
View
@@ -1,20 +1,20 @@
require 'rails'
+require 'rack/mobile-detect'
module MobileFu
autoload :Helper, 'mobile-fu/helper'
autoload :MobilizedStyles, 'mobile-fu/mobilized_styles'
+
+ class Railtie < Rails::Railtie
+ initializer "mobile-fu.configure" do |app|
+ app.config.middleware.use Rack::MobileDetect
+ end
+ Mime::Type.register_alias "text/html", :mobile
+ end
end
module ActionController
module MobileFu
- # These are various strings that can be found in mobile devices. Please feel free
- # to add on to this list.
- MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
- 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
- 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
- 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
- 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
- 'mobile'
def self.included(base)
base.extend ClassMethods
@@ -42,6 +42,7 @@ def has_mobile_fu(test_mode = false)
helper_method :is_mobile_device?
helper_method :in_mobile_view?
helper_method :is_device?
+ helper_method :mobile_device
end
def is_mobile_device?
@@ -89,7 +90,11 @@ def in_mobile_view?
# the device making the request is matched to a device in our regex.
def is_mobile_device?
- request.user_agent.to_s.downcase =~ Regexp.new(ActionController::MobileFu::MOBILE_USER_AGENTS)
+ !!mobile_device
+ end
+
+ def mobile_device
+ request.headers['X_MOBILE_DEVICE']
end
# Can check for a specific user agent
View
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency 'rails'
+ s.add_dependency 'rack-mobile-detect'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rdoc'
end

0 comments on commit 3776362

Please sign in to comment.