Module: ActionController::Layout

Defined in:
lib/action_controller/layout.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/action_controller/layout.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    class << self
      alias_method_chain :inherited, :layout
    end
  end
end

Instance Method Details

#active_layout(passed_layout = nil) ⇒ Object

Returns the name of the active layout. If the layout was specified as a method reference (through a symbol), this method is called and the return value is used. Likewise if the layout was specified as an inline method (through a proc or method object). If the layout was defined without a directory, layouts is assumed. So layout "weblog/standard" will return weblog/standard, but layout "standard" will return layouts/standard.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/action_controller/layout.rb', line 218

def active_layout(passed_layout = nil)
  layout = passed_layout || self.class.default_layout(default_template_format)
  active_layout = case layout
    when String then layout
    when Symbol then __send__(layout)
    when Proc   then layout.call(self)
  end

  # Explicitly passed layout names with slashes are looked up relative to the template root,
  # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative
  # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from.
  if active_layout
    if active_layout.include?('/') && ! layout_directory?(active_layout)
      active_layout
    else
      "layouts/#{active_layout}"
    end
  end
end