aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/new_base/layouts.rb
blob: bf5b14c4e1662cde57d8647b6c69b0a69e223f0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module ActionController
  module Layouts
    extend ActiveSupport::DependencyModule

    depends_on ActionController::Renderer
    depends_on AbstractController::Layouts
    
    module ClassMethods
      def _implied_layout_name
        controller_path
      end
    end
    
    def render_to_body(options)
      # render :text => ..., :layout => ...
      # or
      # render :anything_else
      if (!options.key?(:text) && !options.key?(:inline) && !options.key?(:partial)) || options.key?(:layout)
        options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _default_layout
      end
      
      super
    end
    
  private
  
    def _layout_for_option(name)
      case name
      when String     then _layout_for_name(name)
      when true       then _default_layout(true)
      when false, nil then nil
      else
        raise ArgumentError, 
          "String, true, or false, expected for `layout'; you passed #{name.inspect}"        
      end
    end
    
  end
end