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

.append_features(base) ⇒ Object



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

def self.append_features(base)
  super
  base.extend(ClassMethods)
  base.class_eval do
    alias_method :render_without_layout, :render
    alias_method :render, :render_with_layout
  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.



128
129
130
131
132
133
134
135
136
# File 'lib/action_controller/layout.rb', line 128

def active_layout(passed_layout = nil)
  layout = passed_layout || self.class.read_inheritable_attribute("layout")
  active_layout = case layout
    when Symbol then send(layout)
    when Proc   then layout.call(self)
    when String then layout
  end
  active_layout.include?("/") ? active_layout : "layouts/#{active_layout}" if active_layout
end

#render_with_layout(template_name = "#{controller_name}/#{action_name}", status = nil, layout = nil) ⇒ Object

:nodoc:



138
139
140
141
142
143
144
145
146
147
# File 'lib/action_controller/layout.rb', line 138

def render_with_layout(template_name = "#{controller_name}/#{action_name}", status = nil, layout = nil) #:nodoc:
  if layout ||= active_layout
    add_variables_to_assigns
    logger.info("Rendering #{template_name} within #{layout}") unless logger.nil?
    @content_for_layout = @template.render_file(template_name, true)
    render_without_layout(layout, status)
  else
    render_without_layout(template_name, status)
  end
end