Module: Ramaze::Helper::Layout

Defined in:
lib/ramaze/helper/layout.rb

Overview

Provides wrapper methods for a higher-level approach than the core layout method. The layout() method that comes with Innate/Ramaze is fairly basic as it only allows you to specify a single layout to always use or a block giving you some extra flexibility. The latter however is still a bit of a pain when dealing with many custom layouts in a single controller. Meet the Layout helper. This helper provides a single method (since April 2011, it used to provide more) called "set_layout". This method allows you to specify a number of layouts and the methods for which these layouts should be used.

Examples

The most basic example is simply setting a layout as you would do with the layout() method:

set_layout 'default'

This of course is very boring, time to add some more spices to our code:

set_layout 'default' => [:index]

Woah! What just happened? It's quite easy actually, we merely defined that the layout called "default" should be used for the index method only. Pretty sweet huh? It gets even better:

set_layout 'default' => [:index, :edit], 'alternative' => [:add, :process]

A few things changed. First of all there are now two key/value groups. Each group defines a layout (the key) and a set of methods (the value) for which each layout should be used. In this case the layout "default" will be used for index() and edit() but the layout "alternative" will be used for add() and process().

Last but not least, multiple calls to set_layout will no longer override any existing settings unless you actually specify the same method with a different layout. This is possible because the set_layout method stores all these details in an instance variable called "_ramaze_layouts".

Author:

Defined Under Namespace

Modules: SingletonMethods

Class Method Summary (collapse)

Class Method Details

+ (Object) included(into)

Extends the class that included this module so that the methods that this helper provides can be called outside of instance of class methods.

Parameters:

  • into (Object)

    The class that included this module.

Author:

  • Michael Fellinger

  • Pistos



56
57
58
# File 'lib/ramaze/helper/layout.rb', line 56

def self.included(into)
  into.extend SingletonMethods
end