Module: Ramaze::Helper::Layout::SingletonMethods

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) set_layout(hash_or_layout)

The set_layout method allows you to specify a number of methods and their layout. This allows you to use layout A for methods 1, 2 and 3 but layout B for method 4.

Examples:

# The key is the layout, the value an array of methods
set_layout 'default' => [:method_1], 'alternative' => [:method_2]

# We can combine this method with layout()
layout 'default'
set_layout 'alternative' => [:method_1]

# This is also perfectly fine
set_layout 'default'

Parameters:

  • hash_or_layout (String, Symbol, #to_hash)

    In case it's a String or Symbol it will directly be used as the layout. When setting a Hash this hash should have it's keys set to the layouts and it's values to an array of methods that use the specific layout. For more information see the examples.

Author:

  • Yorick Peterse

  • Michael Fellinger

  • Pistos

Since:

  • 2011-04-07



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ramaze/helper/layout.rb', line 89

def set_layout(hash_or_layout)
  @_ramaze_layouts    ||= {}
  @_ramaze_old_layout ||= trait[:layout]

  # Extract the layout to use
  if hash_or_layout.respond_to?(:to_hash)
    # Invert the method/layout hash and save them so they don't get lost
    hash_or_layout.to_hash.each do |layout, layout_methods|
      layout_methods.each do |layout_method|
        @_ramaze_layouts[layout_method.to_s] = layout.to_s
      end
    end

    layout do |path, wish|
      path = path.to_s

      if @_ramaze_layouts.key?(path)
        use_layout = @_ramaze_layouts[path.to_s]
      # Use the old layout
      elsif @_ramaze_old_layout.respond_to?(:call)
        use_layout = @_ramaze_old_layout.call(path, wish)
      else
        use_layout = @_ramaze_old_layout
      end

      use_layout
    end
  else
    layout { |path| hash_or_layout }
  end
end

- (Object) set_layout_except(hash_or_layout)

Deprecated.

because it's not longer useful



122
123
124
# File 'lib/ramaze/helper/layout.rb', line 122

def set_layout_except(hash_or_layout)
  Ramaze.deprecated('set_layout_except', 'set_layout')
end