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
11
12
13
14
15
# File 'lib/action_controller/layout.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    # NOTE: Can't use alias_method_chain here because +render_without_layout+ is already
    # defined as a publicly exposed method
    alias_method :render_with_no_layout, :render
    alias_method :render, :render_with_a_layout

    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.



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/action_controller/layout.rb', line 223

def active_layout(passed_layout = nil)
  layout = passed_layout || self.class.default_layout(response.template.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