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.
@example
# 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'
@param [String, Symbol, #] hash_or_layout
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 @author Michael Fellinger @author Pistos @since 2011-04-07
# File lib/ramaze/helper/layout.rb, line 89 89: def set_layout(hash_or_layout) 90: @_ramaze_layouts ||= {} 91: @_ramaze_old_layout ||= trait[:layout] 92: 93: # Extract the layout to use 94: if hash_or_layout.respond_to?(:to_hash) 95: # Invert the method/layout hash and save them so they don't get lost 96: hash_or_layout.to_hash.each do |layout, layout_methods| 97: layout_methods.each do |layout_method| 98: @_ramaze_layouts[layout_method.to_s] = layout.to_s 99: end 100: end 101: 102: layout do |path, wish| 103: path = path.to_s 104: 105: if @_ramaze_layouts.key?(path) 106: use_layout = @_ramaze_layouts[path.to_s] 107: # Use the old layout 108: elsif @_ramaze_old_layout.respond_to?(:call) 109: use_layout = @_ramaze_old_layout.call(path, wish) 110: else 111: use_layout = @_ramaze_old_layout 112: end 113: 114: use_layout 115: end 116: else 117: layout { |path| hash_or_layout } 118: end 119: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.