Changeset 9194
- Timestamp:
- 04/01/08 07:39:04 (6 months ago)
- Files:
-
- trunk/actionpack/lib/action_controller/layout.rb (modified) (11 diffs)
- trunk/actionpack/test/controller/request_test.rb (modified) (1 diff)
- trunk/actionpack/test/template/text_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/layout.rb
r8862 r9194 66 66 # 67 67 # 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 69 69 # <tt>app/views/layouts/weblog.erb</tt> or <tt>app/views/layouts/weblog.builder</tt> exists then it will be automatically set as 70 70 # 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 72 72 # no layout explicitly assigned with the +layout+ method. Nested controllers use the same folder structure for automatic layout. 73 73 # assignment. So an Admin::WeblogController will look for a template named <tt>app/views/layouts/admin/weblog.erb</tt>. 74 74 # Setting a layout explicitly will always override the automatic behaviour for the controller where the layout is set. 75 75 # 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. 77 77 # 78 78 # == Inheritance for layouts … … 114 114 # end 115 115 # 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 117 117 # is logged in or not. 118 118 # … … 133 133 # 134 134 # 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 136 136 # <tt>:only</tt> and <tt>:except</tt> options can be passed to the layout call. For example: 137 137 # 138 138 # class WeblogController < ActionController::Base 139 139 # layout "weblog_standard", :except => :rss 140 # 140 # 141 141 # # ... 142 142 # 143 143 # end 144 144 # 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 146 146 # around the rendered view. 147 147 # 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 149 149 # #<tt>:except => [ :rss, :text_only ]</tt> is valid, as is <tt>:except => :rss</tt>. 150 150 # 151 151 # == Using a different layout in the action render call 152 # 152 # 153 153 # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above. 154 154 # Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller. … … 177 177 @layout_conditions ||= read_inheritable_attribute("layout_conditions") 178 178 end 179 179 180 180 def default_layout(format) #:nodoc: 181 layout = read_inheritable_attribute("layout") 181 layout = read_inheritable_attribute("layout") 182 182 return layout unless read_inheritable_attribute("auto_layout") 183 183 @default_layout ||= {} … … 185 185 @default_layout[format] 186 186 end 187 187 188 188 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 194 192 private 195 193 def inherited_with_layout(child) … … 208 206 conditions.inject({}) {|hash, (key, value)| hash.merge(key => [value].flatten.map {|action| action.to_s})} 209 207 end 210 208 211 209 def default_layout_with_format(format, layout) 212 210 list = layout_list … … 230 228 when Proc then layout.call(self) 231 229 end 232 230 233 231 # Explicitly passed layout names with slashes are looked up relative to the template root, 234 232 # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative … … 246 244 def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc: 247 245 template_with_options = options.is_a?(Hash) 248 246 249 247 if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) 250 248 assert_existence_of_template_file(layout) … … 273 271 274 272 def candidate_for_layout?(options) 275 (options.has_key?(:layout) && options[:layout] != false) || 273 (options.has_key?(:layout) && options[:layout] != false) || 276 274 options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? && 277 275 !template_exempt_from_layout?(options[:template] || default_template_name(options[:action])) … … 299 297 only.include?(action_name) 300 298 when except = conditions[:except] 301 !except.include?(action_name) 299 !except.include?(action_name) 302 300 else 303 301 true … … 307 305 end 308 306 end 309 307 310 308 def layout_directory?(layout_name) 311 309 @template.finder.find_template_extension_from_handler(File.join('layouts', layout_name)) trunk/actionpack/test/controller/request_test.rb
r9124 r9194 836 836 837 837 # Ruby CGI doesn't handle multipart/mixed for us. 838 assert_kind_of String, params['files'] 839 assert_equal 19756, params['files'].size 838 files = params['files'] 839 assert_kind_of String, files 840 files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) 841 assert_equal 19756, files.size 840 842 end 841 843 trunk/actionpack/test/template/text_helper_test.rb
r9083 r9194 137 137 def test_excerpt_with_utf8 138 138 with_kcode('u') do 139 assert_equal("... ï¬ciency could not be...", excerpt("That's why eï¬ciency could not be helped", 'could', 8))139 assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) 140 140 end 141 141 with_kcode('none') do 142 assert_equal("...\203ciency could not be...", excerpt("That's why e ï¬ciency could not be helped", 'could', 8))142 assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) 143 143 end 144 144 end 145 145 else 146 146 def test_excerpt_with_utf8 147 assert_equal("... ï¬ciency could not be...".force_encoding('UTF-8'), excerpt("That's why eï¬ciency could not be helped".force_encoding('UTF-8'), 'could', 8))148 assert_equal("...\203ciency could not be...", excerpt("That's why e ï¬ciency could not be helped", 'could', 8))147 assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8)) 148 assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) 149 149 end 150 150 end