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
204
205
# 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 = nil, deprecated_status = nil, deprecated_layout = nil) ⇒ Object

:nodoc:


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/action_controller/layout.rb', line 207

def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil) #:nodoc:
  template_with_options = options.is_a?(Hash)

  if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout))
    options = options.merge :layout => false if template_with_options
    logger.info("Rendering #{options} within #{layout}") if logger

    if template_with_options
      content_for_layout = render_with_no_layout(options)
      deprecated_status = options[:status] || deprecated_status
    else
      content_for_layout = render_with_no_layout(options, deprecated_status)
    end

    erase_render_results
    @template.instance_variable_set("@content_for_layout", content_for_layout)
    render_text(@template.render_file(layout, true), deprecated_status)
  else
    render_with_no_layout(options, deprecated_status)
  end
end