Module: Cms::MobileAware
Instance Method Summary collapse
-
#determine_page_layout ⇒ String
Looks for a mobile template if the request is mobile, falling back to the html template if it can’t be found.
-
#respond_as_mobile? ⇒ Boolean
Because of caching, CMS pages should only return mobile content on a separate subdomain.
-
#select_cache_directory ⇒ Object
This is changing a class attribute in order to write the page cache to a different directory based on mobile vs full page request.
Methods included from DefaultCaches
#cms_cache_directory, #mobile_cache_directory
Instance Method Details
#determine_page_layout ⇒ String
Looks for a mobile template if the request is mobile, falling back to the html template if it can’t be found.
10 11 12 13 14 15 16 |
# File 'lib/cms/mobile_aware.rb', line 10 def determine_page_layout if respond_as_mobile? mobile_exists = template_exists?(@page.layout_name, "layouts/mobile") return @page.layout(:mobile) if mobile_exists end @page.layout(:full) end |
#respond_as_mobile? ⇒ Boolean
Because of caching, CMS pages should only return mobile content on a separate subdomain. or if a CMS editor wants to see the mobile version of the page.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cms/mobile_aware.rb', line 32 def respond_as_mobile? log "For mobile optimization, checking the subdomain for '#{request.domain}' is '#{request.subdomain}'." if params[:template] =='mobile' session[:mobile_mode] = true elsif params[:template] =='full' session[:mobile_mode] = false end request.subdomain == "m" || (session[:mobile_mode] == true && current_user.able_to?(:edit_content)) end |
#select_cache_directory ⇒ Object
This is changing a class attribute in order to write the page cache to a different directory based on mobile vs full page request.
20 21 22 23 24 25 26 |
# File 'lib/cms/mobile_aware.rb', line 20 def select_cache_directory if respond_as_mobile? self.class.page_cache_directory = mobile_cache_directory else self.class.page_cache_directory = cms_cache_directory end end |