Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

allow the mobile format to be configured. #18

Open
wants to merge 2 commits into from

2 participants

@ahoward

our application is cleanly partitioned under /m so we use the code, but specifiying the format is very useful.

@benlangfeld

This project is abandoned. Please see the active fork at http://github.com/benlangfeld/mobile-fu. Please test with the released gem and master branch of the new home for the project, and file an issue on the other repo if you still have problems.

See #40.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 6 deletions.
  1. +27 −6 lib/mobile_fu.rb
View
33 lib/mobile_fu.rb
@@ -27,7 +27,12 @@ module ClassMethods
# has_mobile_fu(true)
# end
- def has_mobile_fu(test_mode = false)
+ #def has_mobile_fu(test_mode = false)
+ def has_mobile_fu(*args)
+ options = args.extract_options!.to_options!
+ test_mode = args.shift || options[:test]
+ format = options[:format] || :mobile
+
include ActionController::MobileFu::InstanceMethods
if test_mode
@@ -36,6 +41,8 @@ def has_mobile_fu(test_mode = false)
before_filter :set_mobile_format
end
+ mobile_format(format)
+
helper_method :is_mobile_device?
helper_method :in_mobile_view?
helper_method :is_device?
@@ -52,23 +59,37 @@ def in_mobile_view?
def is_device?(type)
@@is_device
end
+
+ def mobile_format(*value)
+ @@mobile_format = value.shift.to_s.to_sym unless value.blank?
+ @@mobile_format ||= :mobile
+ end
+
+ def mobile_format=(value)
+ mobile_format(value)
+ end
end
module InstanceMethods
-
- # Forces the request format to be :mobile
+
+ # Forces the request format to be mobile_format
def force_mobile_format
- request.format = :mobile
+ request.format = mobile_format
session[:mobile_view] = true if session[:mobile_view].nil?
end
+
+ # Returns the configured mobile_format - :mobile by default
+ def mobile_format
+ self.class.mobile_format
+ end
# Determines the request format based on whether the device is mobile or if
# the user has opted to use either the 'Standard' view or 'Mobile' view.
def set_mobile_format
if is_mobile_device? && !request.xhr?
- request.format = session[:mobile_view] == false ? :html : :mobile
+ request.format = session[:mobile_view] == false ? :html : mobile_format
session[:mobile_view] = true if session[:mobile_view].nil?
end
end
@@ -99,4 +120,4 @@ def is_device?(type)
end
-ActionController::Base.send(:include, ActionController::MobileFu)
+ActionController::Base.send(:include, ActionController::MobileFu)
Something went wrong with that request. Please try again.