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

def self.append_features(base)
  super
  base.class_eval do
    alias_method :render_with_no_layout, :render
    alias_method :render, :render_with_a_layout

    class << self
      alias_method :inherited_without_layout, :inherited
    end
  end
  base.extend(ClassMethods)
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.



195
196
197
198
199
200
201
202
203
# File 'lib/action_controller/layout.rb', line 195

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_a_layout(options = {}, deprecated_status = nil, deprecated_layout = nil) ⇒ Object

:nodoc:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/action_controller/layout.rb', line 205

def render_with_a_layout(options = {}, deprecated_status = nil, deprecated_layout = nil) #:nodoc:
  options = render_with_a_layout_options(options)
  if (layout = pick_layout(options, deprecated_layout))
    logger.info("Rendering #{options[:template]} within #{layout}") unless logger.nil?

    @content_for_layout = render_with_no_layout(options.merge(:layout => false))
    erase_render_results

    add_variables_to_assigns
    render_with_no_layout(options.merge({ :text => @template.render_file(layout, true), :status => options[:status] || deprecated_status }))
  else
    render_with_no_layout(options, deprecated_status)
  end
end