massage.rb

Path: massage/lib/massage.rb
Last Update: Sat Jul 28 15:49:01 +0800 2007
Authors:Kang-min Liu (gugod@gugod.org), Lukhnos D. Liu (lukhnos@handlino.com)
Copyright:Copyright (c) 2007 Handlino Inc.
License:Distributed under the New BSD License

Massage is a plugin that makes it very easy to turn your Rails App Into a "single page application" (SPA). An SPA is a Google Mail-like application, in which every controller action is rendered in an HTML element, instead of requiring the flushing of the entire HTML document (ie. page loading).

To enable SPA, simply install the plug-in, and add this line:

  spa :only => [:index, :settings]    # or :except => [...]

Then when action index or settings is requested as an XHR, the plug-in knows the strip the layout and only render the content into a designated element ("content" by default; changeable).

massage makes use of RJS to enable the SPA techniques. RJS by default requires prototype.js to be included. So make sure it‘s there in your template or layout code.

Methods

Constants

DEFAULT_UPDATE_ELEMENT = "content"

External Aliases

template_exempt_from_layout? -> rails_template_exempt_from_layout?

Public Class methods

Turns ("massages") the controller into an SPA-capable controller. This class method adds an around filter to controller actions So they can serve content from both xhr and non-xhr requests.

The options include:

  • :only, like that of before_filter, after_filter
  • :except, also like that of before_filter, after_filter
  • :update_element, the element in which to render and update the content, set to "content" by default. Note that in your layout code a DOM element (DIV by default) must bear the same id

Public Instance methods

Overrider this from ActionController::Base for spa. If we need to do spa for xhr, then we‘ll need to remove layout. Making it look like render :layout => nil.

[Validate]