Skip to content

Commit

Permalink
Switch to using rack-mobile-detect
Browse files Browse the repository at this point in the history
* Also tidy up a little
  • Loading branch information
benlangfeld committed Apr 27, 2011
1 parent 062ef97 commit 3776362
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 98 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
89 changes: 0 additions & 89 deletions Gemfile.lock

This file was deleted.

23 changes: 14 additions & 9 deletions lib/mobile-fu.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mobile-fu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.