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

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

Instance Method Summary collapse

Instance Method Details

#set_layout(hash_or_the_layout) ⇒ Object

Examples:

Use a layout named ‘default’ on all actions of the controller:

set_layout 'default'

Use a layout named ‘default’ on just the index and admin actions:

set_layout 'default' => [ :index, :admin ]

Parameters:

  • Either (String Hash)

    a layout name, or a single-element Hash which maps a layout name to an Array containing a whitelist of action names

See Also:

Author:

  • Pistos, manveru



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ramaze/helper/layout.rb', line 56

def set_layout(hash_or_the_layout)
  if hash_or_the_layout.respond_to?(:to_hash)
    f = hash_or_the_layout.to_hash.find{|k,v| k && v }
    the_layout = f[0]
    whitelist = f[1].map{|action| action.to_s }
  else
    the_layout = hash_or_the_layout
  end

  layout do |path, wish|
    if whitelist.nil? || whitelist.include?(path.to_s)
      the_layout
    end
  end
end

#set_layout_except(hash_or_the_layout) ⇒ Object

Examples:

Use a layout named ‘default’ on all actions except the user_data action:

set_layout_except 'default' => [ :user_data ]

Parameters:

  • Either (String Hash)

    a layout name, or a single-element Hash which maps a layout name to an Array containing a blacklist of action names

See Also:

Author:

  • Pistos, manveru



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ramaze/helper/layout.rb', line 79

def set_layout_except(hash_or_the_layout)
  if hash_or_the_layout.respond_to?(:to_hash)
    f = hash_or_the_layout.to_hash.find{|k,v| k && v }
    the_layout = f[0]
    blacklist = f[1].map{|action| action.to_s }
  else
    the_layout = hash_or_the_layout
  end

  layout do |path, wish|
    if blacklist.nil? || !blacklist.include?(path.to_s)
      the_layout
    end
  end
end