Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
04/01/08 07:39:04 (8 months ago)
Author:
bitsweat
Message:

Ruby 1.9 compat: encoding and multibyte test fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/layout.rb

    r8862 r9194  
    6666    # 
    6767    # If there is a template in <tt>app/views/layouts/</tt> with the same name as the current controller then it will be automatically 
    68     # set as that controller's layout unless explicitly told otherwise. Say you have a WeblogController, for example. If a template named  
     68    # set as that controller's layout unless explicitly told otherwise. Say you have a WeblogController, for example. If a template named 
    6969    # <tt>app/views/layouts/weblog.erb</tt> or <tt>app/views/layouts/weblog.builder</tt> exists then it will be automatically set as 
    7070    # the layout for your WeblogController. You can create a layout with the name <tt>application.erb</tt> or <tt>application.builder</tt> 
    71     # and this will be set as the default controller if there is no layout with the same name as the current controller and there is  
     71    # and this will be set as the default controller if there is no layout with the same name as the current controller and there is 
    7272    # no layout explicitly assigned with the +layout+ method. Nested controllers use the same folder structure for automatic layout. 
    7373    # assignment. So an Admin::WeblogController will look for a template named <tt>app/views/layouts/admin/weblog.erb</tt>. 
    7474    # Setting a layout explicitly will always override the automatic behaviour for the controller where the layout is set. 
    7575    # Explicitly setting the layout in a parent class, though, will not override the child class's layout assignment if the child 
    76     # class has a layout with the same name.  
     76    # class has a layout with the same name. 
    7777    # 
    7878    # == Inheritance for layouts 
     
    114114    #       end 
    115115    # 
    116     # Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing  
     116    # Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing 
    117117    # is logged in or not. 
    118118    # 
     
    133133    # 
    134134    # If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering 
    135     # a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The  
     135    # a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The 
    136136    # <tt>:only</tt> and <tt>:except</tt> options can be passed to the layout call. For example: 
    137137    # 
    138138    #   class WeblogController < ActionController::Base 
    139139    #     layout "weblog_standard", :except => :rss 
    140     #  
     140    # 
    141141    #     # ... 
    142142    # 
    143143    #   end 
    144144    # 
    145     # This will assign "weblog_standard" as the WeblogController's layout  except for the +rss+ action, which will not wrap a layout  
     145    # This will assign "weblog_standard" as the WeblogController's layout  except for the +rss+ action, which will not wrap a layout 
    146146    # around the rendered view. 
    147147    # 
    148     # Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so  
     148    # Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so 
    149149    # #<tt>:except => [ :rss, :text_only ]</tt> is valid, as is <tt>:except => :rss</tt>. 
    150150    # 
    151151    # == Using a different layout in the action render call 
    152     #  
     152    # 
    153153    # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above. 
    154154    # Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller. 
     
    177177        @layout_conditions ||= read_inheritable_attribute("layout_conditions") 
    178178      end 
    179        
     179 
    180180      def default_layout(format) #:nodoc: 
    181         layout = read_inheritable_attribute("layout")                  
     181        layout = read_inheritable_attribute("layout") 
    182182        return layout unless read_inheritable_attribute("auto_layout") 
    183183        @default_layout ||= {} 
     
    185185        @default_layout[format] 
    186186      end 
    187        
     187 
    188188      def layout_list #:nodoc: 
    189         view_paths.collect do |path| 
    190           Dir["#{path}/layouts/**/*"] 
    191         end.flatten 
    192       end 
    193        
     189        Array(view_paths).sum([]) { |path| Dir["#{path}/layouts/**/*"] } 
     190      end 
     191 
    194192      private 
    195193        def inherited_with_layout(child) 
     
    208206          conditions.inject({}) {|hash, (key, value)| hash.merge(key => [value].flatten.map {|action| action.to_s})} 
    209207        end 
    210          
     208 
    211209        def default_layout_with_format(format, layout) 
    212210          list = layout_list 
     
    230228        when Proc   then layout.call(self) 
    231229      end 
    232        
     230 
    233231      # Explicitly passed layout names with slashes are looked up relative to the template root, 
    234232      # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative 
     
    246244      def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc: 
    247245        template_with_options = options.is_a?(Hash) 
    248          
     246 
    249247        if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) 
    250248          assert_existence_of_template_file(layout) 
     
    273271 
    274272      def candidate_for_layout?(options) 
    275         (options.has_key?(:layout) && options[:layout] != false) ||  
     273        (options.has_key?(:layout) && options[:layout] != false) || 
    276274          options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? && 
    277275          !template_exempt_from_layout?(options[:template] || default_template_name(options[:action])) 
     
    299297              only.include?(action_name) 
    300298            when except = conditions[:except] 
    301               !except.include?(action_name)  
     299              !except.include?(action_name) 
    302300            else 
    303301              true 
     
    307305        end 
    308306      end 
    309        
     307 
    310308      def layout_directory?(layout_name) 
    311309        @template.finder.find_template_extension_from_handler(File.join('layouts', layout_name))