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
109 110 111 112 113 114 |
# File 'lib/mobile-fu.rb', line 109 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
117 118 119 120 121 122 |
# File 'lib/mobile-fu.rb', line 117 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.
141 142 143 144 |
# File 'lib/mobile-fu.rb', line 141 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.
149 150 151 152 |
# File 'lib/mobile-fu.rb', line 149 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’)
172 173 174 |
# File 'lib/mobile-fu.rb', line 172 def is_device?(type) request.user_agent.to_s.downcase.include? type.to_s.downcase end |
#is_mobile_device? ⇒ Boolean
161 162 163 |
# File 'lib/mobile-fu.rb', line 161 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.
157 158 159 |
# File 'lib/mobile-fu.rb', line 157 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
178 179 180 181 182 183 184 |
# File 'lib/mobile-fu.rb', line 178 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
165 166 167 |
# File 'lib/mobile-fu.rb', line 165 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
189 190 191 |
# File 'lib/mobile-fu.rb', line 189 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.
128 129 130 131 132 133 134 135 136 |
# File 'lib/mobile-fu.rb', line 128 def set_mobile_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
103 104 105 |
# File 'lib/mobile-fu.rb', line 103 def set_request_format(force_mobile = false) force_mobile ? force_mobile_format : set_mobile_format end |