Module: Cms::MobileAware

Includes:
DefaultCaches
Included in:
ContentController
Defined in:
lib/cms/mobile_aware.rb

Instance Method Summary collapse

Methods included from DefaultCaches

#cms_cache_directory, #mobile_cache_directory

Instance Method Details

#determine_page_layoutString

Looks for a mobile template if the request is mobile, falling back to the html template if it can’t be found.

Returns:

  • (String)

    relative path/name of the layout to be rendered by a page (i.e. ‘layouts/templates/default’)



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.

Returns:

  • (Boolean)

    true if this request is considered ‘mobile’, false otherwise



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_directoryObject

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