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

def self.included(base)
  base.extend(ClassMethods)
  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
      alias_method :inherited, :inherited_with_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.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/action_controller/layout.rb', line 213

def active_layout(passed_layout = nil)
  layout = passed_layout || self.class.default_layout

  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

#render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) ⇒ Object

:nodoc:



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/action_controller/layout.rb', line 234

def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #: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, &block)
      deprecated_status = options[:status] || deprecated_status
    else
      content_for_layout = render_with_no_layout(options, deprecated_status, &block)
    end

    erase_render_results
    add_variables_to_assigns
    @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, &block)
  end
end