Module: ActionController::MobileFu::InstanceMethods
- Defined in:
- lib/mobile-fu.rb
Instance Method Summary collapse
-
#force_mobile_format ⇒ Object
Forces the request format to be :mobile.
-
#force_tablet_format ⇒ Object
Forces the request format to be :tablet.
-
#in_mobile_view? ⇒ Boolean
Returns either true or false depending on whether or not the format of the request is either :mobile or not.
-
#in_tablet_view? ⇒ Boolean
Returns either true or false depending on whether or not the format of the request is either :tablet or not.
-
#is_device?(type) ⇒ Boolean
Can check for a specific user agent e.g., is_device?(‘iphone’) or is_device?(‘mobileexplorer’).
- #is_mobile_device? ⇒ Boolean
-
#is_tablet_device? ⇒ Boolean
Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.
-
#mobile_action? ⇒ Boolean
Returns true if current action is supposed to use mobile format See #has_mobile_fu_for.
- #mobile_device ⇒ Object
-
#mobile_exempt? ⇒ Boolean
Returns true if current action isn’t supposed to use mobile format See #has_no_mobile_fu_for.
-
#set_mobile_format ⇒ Object
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 or ‘Tablet’ view.
- #set_request_format(force_mobile = false) ⇒ Object (also: #set_device_type)
Instance Method Details
#force_mobile_format ⇒ Object
Forces the request format to be :mobile
110 111 112 113 114 115 |
# File 'lib/mobile-fu.rb', line 110 def force_mobile_format unless request.xhr? request.format = :mobile session[:mobile_view] = true if session[:mobile_view].nil? end end |
#force_tablet_format ⇒ Object
Forces the request format to be :tablet
118 119 120 121 122 123 |
# File 'lib/mobile-fu.rb', line 118 def force_tablet_format unless request.xhr? request.format = :tablet session[:tablet_view] = true if session[:tablet_view].nil? end end |
#in_mobile_view? ⇒ Boolean
Returns either true or false depending on whether or not the format of the request is either :mobile or not.
143 144 145 146 |
# File 'lib/mobile-fu.rb', line 143 def in_mobile_view? return false unless request.format request.format.to_sym == :mobile end |
#in_tablet_view? ⇒ Boolean
Returns either true or false depending on whether or not the format of the request is either :tablet or not.
151 152 153 154 |
# File 'lib/mobile-fu.rb', line 151 def in_tablet_view? return false unless request.format request.format.to_sym == :tablet end |
#is_device?(type) ⇒ Boolean
Can check for a specific user agent e.g., is_device?(‘iphone’) or is_device?(‘mobileexplorer’)
174 175 176 |
# File 'lib/mobile-fu.rb', line 174 def is_device?(type) request.user_agent.to_s.downcase.include? type.to_s.downcase end |
#is_mobile_device? ⇒ Boolean
163 164 165 |
# File 'lib/mobile-fu.rb', line 163 def is_mobile_device? !is_tablet_device? && !!mobile_device end |
#is_tablet_device? ⇒ Boolean
Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.
159 160 161 |
# File 'lib/mobile-fu.rb', line 159 def is_tablet_device? ::MobileFu::Tablet.is_a_tablet_device? request.user_agent end |
#mobile_action? ⇒ Boolean
Returns true if current action is supposed to use mobile format See #has_mobile_fu_for
180 181 182 183 184 185 186 |
# File 'lib/mobile-fu.rb', line 180 def mobile_action? if self.class.instance_variable_get("@mobile_include_actions").nil? #Now we know we dont have any includes, maybe excludes? return !mobile_exempt? else self.class.instance_variable_get("@mobile_include_actions").try(:include?, params[:action].try(:to_sym)) end end |
#mobile_device ⇒ Object
167 168 169 |
# File 'lib/mobile-fu.rb', line 167 def mobile_device request.headers['X_MOBILE_DEVICE'] end |
#mobile_exempt? ⇒ Boolean
Returns true if current action isn’t supposed to use mobile format See #has_no_mobile_fu_for
191 192 193 |
# File 'lib/mobile-fu.rb', line 191 def mobile_exempt? self.class.instance_variable_get("@mobile_exempt_actions").try(:include?, params[:action].try(:to_sym)) end |
#set_mobile_format ⇒ Object
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 or ‘Tablet’ view.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/mobile-fu.rb', line 129 def set_mobile_format return unless request.format if request.format.html? && mobile_action? && is_mobile_device? && !request.xhr? request.format = :mobile unless session[:mobile_view] == false session[:mobile_view] = true if session[:mobile_view].nil? elsif request.format.html? && mobile_action? && is_tablet_device? && !request.xhr? request.format = :tablet unless session[:tablet_view] == false session[:tablet_view] = true if session[:tablet_view].nil? end end |
#set_request_format(force_mobile = false) ⇒ Object Also known as: set_device_type
104 105 106 |
# File 'lib/mobile-fu.rb', line 104 def set_request_format(force_mobile = false) force_mobile ? force_mobile_format : set_mobile_format end |