Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 759c2af823
Fetching contributors…

Cannot retrieve contributors at this time

109 lines (73 sloc) 5.852 kb

Mobile Module for BrowserCMS

A 'Mobile First' module that allows any BrowserCMS page to be served in a mobile optimized format for specific mobile devices. Pages can have mobile optimized templates that can reduce their download weight and layout for reduced screen/bandwidth platforms.

Features

  • Developers can define a mobile template for any existing .html.erb template on a project. These template are named the same as the existing templates, but are placed in a separate layouts/mobile directory.
  • View as Mobile: Editors should be able to preview the mobile templates. Once in 'mobile' mode, all pages should be viewed as mobile until they disable it.
  • Mobile assumes a m. subdomain will exist. It will return the mobile template for all requests to pages on that domain.
  • Fallback Templates: If page uses a template which has no mobile counterpart, it will display using its normal template.
  • Agent Redirection: Users on mobile devices can be automatically redirected to the m. site. (Handled via Apache User Agent detection.)
  • Mobile Site Opt Out: Users on mobile device can opt to be redirected to the desktop site if they want. (Handled via a cookie)
  • Mobile caching: The mobile and full sites have their own separate page cache, mean both can be served quickly by Apache.

Installation

To install bcms_mobile, run the following commands in your browsercms project:

$ gem install bcms_mobile
$ rails g cms:install bcms_mobile

This will add a new directory to the project, app/views/layouts/mobile. Delete the following line from your config/production.rb file:

config.action_controller.page_cache_directory = File.join(Rails.root, 'public', 'cache')

Configuring the Cache Directories

Since this module requires a separate top level domain in production (m.), it needs a separate page cache from the 'full' site version. By default, these will be:

public/cache # Full site cache
public/mobile_cache # Mobile Cache

To configure these directories, you can specify new locations in the production.rb via:

config.bcms_mobile_cache_directory = File.join(Rails.root, 'public', 'cache' 'mobile')
config.browsercms_cache_directory = File.join(Rails.root, 'public', 'cache', 'full')

However, the defaults will be used even if you don't specify the cache directories.

Making a Mobile Template

To make a mobile template, you can then copy any page template from your app/views/layouts/templates into the mobile directory. The file name should be the same. Make any necessary edits to 'mobilize' it (i.e. remove sidebars, image, etc). When you view a page in the CMS, you can toggle between the mobile and desktop templates.

Add Full/Mobile Site links

Because the module will automatically redirect mobile users to the mobile site, they may want to visit the full site. So make sure they are conveniently placed on both mobile and full templates. You can do this with the following helpers:

<%= link_to "See the Full Site", full_site_url %>
<%= link_to "See the Mobile Site", mobile_site_url %>

Development

Things to improve

  • The Apache conf file has way too much logic in it. Specifically, the device types and matching rules really can't be tested, at all. We also have to have a 3rd virtual host for the m. site which isn't so hot.

Resources

Getting setup

Working on the bcms_mobile and getting accurate testing requires subdomains enabled locally. If you set up POW, you can use the basic subdomains.

Steps:

$ gem install powder
$ cd bcms_mobile
$ powder link bcms-mobile

This will make the following subdomains available for testing.

Testing Agent Redirection with Passenger/Apache

Using POW will not enable Agent Redirection, since that is configured via Apache. To adequately test this, you will need to enable Apache/Passenger and configure the virtual hosts as documented here. On OSX, you can can create a new file called /private/etc/apache2/other/bcms_mobile.conf . This page here has a sample configuration file

To get configuration right, need Apache/Passenger so you can fool around with Apache specific rewrite rules. See these instructions for setting up Passenger on OSX.

Jump to Line
Something went wrong with that request. Please try again.