Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow the mobile format to be configured. #18

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions lib/mobile_fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -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
Expand Down Expand Up @@ -99,4 +120,4 @@ def is_device?(type)

end

ActionController::Base.send(:include, ActionController::MobileFu)
ActionController::Base.send(:include, ActionController::MobileFu)