Skip to content

Commit

Permalink
Mobile Template mode
Browse files Browse the repository at this point in the history
* Editors can switch to mobile mode which allows them to browse the site using mobile templates
* They can toggle back between full/mobile templates using parameters (template=mobile, template=full)
* Need :edit_content permission to be able to switch templates.
  • Loading branch information
peakpg committed Feb 9, 2012
1 parent 5402aea commit ede00dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.markdown
Expand Up @@ -3,6 +3,7 @@
## Features (Completed)

* 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.
* Preview 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.
* Editors always see the desktop template, unless they add a ?template=mobile parameter to the URL of the page they are viewing.
* Mobile assumes a m. subdomain will exist. It will return the mobile template for all requests to pages on that domain.
* If page uses a template which has no mobile counterpart, it will display using its normal template.
Expand Down
14 changes: 14 additions & 0 deletions features/mobile_templates.feature
Expand Up @@ -33,6 +33,20 @@ Feature:
When they request /mobile-page?template=mobile
Then they should see the mobile template

Scenario: Mobile 'mode' is sticky
Given a page exists at /another-page
And a cms editor is logged in
When they request /another-page?template=mobile
Then they request /mobile-page
Then they should see the mobile template

Scenario: Disable Mobile mode
Given a page exists at /another-page
And a cms editor is logged in
When they request /mobile-page?template=mobile
Then they request /mobile-page?template=full
Then they should see the desktop content

Scenario: Guests can't request mobile versions of page
Given a user is browsing the desktop site
When they request /mobile-page?template=mobile
Expand Down
9 changes: 8 additions & 1 deletion lib/bcms_mobile/engine.rb
Expand Up @@ -44,11 +44,18 @@ def configure_cache_directory
# or if a CMS editor wants to see the mobile version of the page.
def respond_as_mobile?
w "Checking the subdomain for #{request.domain} is #{request.subdomain}"
request.subdomain == "m" || (params[:template] =='mobile' && current_user.able_to?(:edit_content))
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

private


# Overrides core behavior to swap layouts based on whether this is a mobile request or not.
def render_page

Expand Down

0 comments on commit ede00dd

Please sign in to comment.