From b7677c96b0071a86fc26f28d02b8e5f330c6ed17 Mon Sep 17 00:00:00 2001 From: "ara.t.howard" Date: Tue, 26 Apr 2011 09:19:35 -0600 Subject: [PATCH 1/2] make :mobile format configurable --- lib/mobile_fu.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/mobile_fu.rb b/lib/mobile_fu.rb index b3aac85..df47270 100644 --- a/lib/mobile_fu.rb +++ b/lib/mobile_fu.rb @@ -52,23 +52,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 +113,4 @@ def is_device?(type) end -ActionController::Base.send(:include, ActionController::MobileFu) \ No newline at end of file +ActionController::Base.send(:include, ActionController::MobileFu) From d18a49c5af2d6182e8f544772514a55cfa339743 Mon Sep 17 00:00:00 2001 From: "ara.t.howard" Date: Tue, 26 Apr 2011 13:07:06 -0600 Subject: [PATCH 2/2] allow configuration via options passed at the class level --- lib/mobile_fu.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/mobile_fu.rb b/lib/mobile_fu.rb index df47270..38c3c3b 100644 --- a/lib/mobile_fu.rb +++ b/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?