Changeset 1588
- Timestamp:
- 07/01/05 23:44:14 (3 years ago)
- Files:
-
- branches/performance/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- branches/performance/actionpack/lib/action_controller/benchmarking.rb (modified) (1 diff)
- branches/performance/actionpack/lib/action_controller/deprecated_renders_and_redirects.rb (modified) (4 diffs)
- branches/performance/actionpack/lib/action_controller/layout.rb (modified) (3 diffs)
- branches/performance/actionpack/lib/action_view/partials.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/performance/actionpack/lib/action_controller/base.rb
r1377 r1588 443 443 444 444 # A unified replacement for the individual renders (work-in-progress). 445 def render(options = {}, deprecated_status = nil)446 # puts "Rendering: #{options.inspect}" 445 def render(options = nil, deprecated_status = nil) 446 # puts "Rendering: #{options.inspect}" if options 447 447 raise DoubleRenderError, "Can only render or redirect once per action" if performed? 448 448 449 449 # Backwards compatibility 450 if !options.is_a?(Hash) 451 template = options || default_template_name 452 assert_existance_of_template_file(template) 453 logger.info("Rendering #{template} (#{options[:status]})") if logger 454 add_variables_to_assigns 455 return render_text(@template.render_file(template, true), options[:status]) 456 end 457 458 if text=options[:text] 450 unless options.is_a?(Hash) 451 return render_file(options || default_template_name, deprecated_status, true) 452 end 453 454 if text = options[:text] 459 455 render_text(text, options[:status]) 460 456 461 457 else 462 add_variables_to_assigns 463 if file=options[:file] 464 use_full_path = options[:use_full_path] 465 assert_existance_of_template_file(file) if use_full_path 466 logger.info("Rendering #{file} (#{options[:status]})") if logger 467 render_text(@template.render_file(file, use_full_path), options[:status]) 458 if file = options[:file] 459 render_file(file, options[:status], options[:use_full_path]) 468 460 469 elsif template=options[:template] 470 assert_existance_of_template_file(template) 471 logger.info("Rendering #{template} (#{options[:status]})") if logger 472 render_text(@template.render_file(template, true), options[:status]) 461 elsif template = options[:template] 462 render_file(template, options[:status], true) 473 463 474 elsif inline =options[:inline]475 render_te xt(@template.render_template(options[:type] || :rhtml, inline), options[:status])464 elsif inline = options[:inline] 465 render_template(inline, options[:status], options[:type]) 476 466 477 elsif action=options[:action] 478 template = default_template_name(action) 479 assert_existance_of_template_file(template) 480 logger.info("Rendering #{template} (#{options[:status]})") if logger 481 render_text(@template.render_file(template, true), options[:status]) 467 elsif action_name = options[:action] 468 render_action(action_name, options[:status]) 482 469 483 elsif partial=options[:partial] 484 if collection=options[:collection] 485 render_text( 486 @template.render_partial_collection( 487 partial == true ? default_template_name : partial, 488 collection, options[:spacer_template], 489 options[:locals] || {} 490 ) || '', 491 options[:status] 492 ) 470 elsif partial = options[:partial] 471 partial = default_template_name if partial == true 472 if collection = options[:collection] 473 render_partial_collection(partial, collection, options[:spacer_template], options[:locals], options[:status]) 493 474 else 494 render_text(@template.render_partial( 495 partial == true ? default_template_name : partial, 496 options[:object], options[:locals] || {} 497 ), 498 options[:status] 499 ) 475 render_partial(partial, options[:object], options[:locals], options[:status]) 500 476 end 477 501 478 elsif options[:nothing] 502 479 render_text("", options[:status]) 503 480 504 481 else 505 template = default_template_name 506 assert_existance_of_template_file(template) 507 logger.info("Rendering #{file} (#{options[:status]})") if logger 508 render_text(@template.render_file(template, true), options[:status]) 482 render_file(default_template_name, options[:status], true) 509 483 510 484 end branches/performance/actionpack/lib/action_controller/benchmarking.rb
r1377 r1588 16 16 end 17 17 18 def render_with_benchmark(options = {}, deprecated_status = nil)18 def render_with_benchmark(options = nil, deprecated_status = nil) 19 19 if logger.nil? 20 20 render_without_benchmark(options, deprecated_status) branches/performance/actionpack/lib/action_controller/deprecated_renders_and_redirects.rb
r1377 r1588 6 6 # "#{template_root}/weblog/show_many.rxml". 7 7 def render_action(action_name, status = nil) #:doc: 8 render :action => action_name, :status => status 8 add_variables_to_assigns 9 template = default_template_name(action_name) 10 assert_existance_of_template_file(template) 11 logger.info("Rendering #{template} (#{status})") if logger 12 render_text(@template.render_file(template, true), status) 9 13 end 10 14 … … 13 17 # "/Users/david/Code/Ruby/template.rxml". 14 18 def render_file(template_path, status = nil, use_full_path = false) #:doc: 15 render :file => template_path, :status => status, :use_full_path => use_full_path 19 add_variables_to_assigns 20 assert_existance_of_template_file(template_path) if use_full_path 21 logger.info("Rendering #{template_path} (#{status})") if logger 22 render_text(@template.render_file(template_path, use_full_path), status) 16 23 end 17 24 … … 19 26 # you'd call <tt>render_template "Hello, <%= @user.name %>"</tt> to greet the current user. Or if you want to render as Builder 20 27 # template, you could do <tt>render_template "xml.h1 @user.name", nil, "rxml"</tt>. 21 def render_template(template, status = nil, type = "rhtml") #:doc: 22 render :inline => template, :status => status, :type => type 28 def render_template(template, status = nil, type = :rhtml) #:doc: 29 add_variables_to_assigns 30 render_text(@template.render_template(type, template), status) 23 31 end 24 32 … … 46 54 # end 47 55 # end 48 def render_partial(partial_path = default_template_name, object = nil, local_assigns = {}) #:doc: 49 render :partial => partial_path, :object => object, :locals => local_assigns 56 def render_partial(partial_path = default_template_name, object = nil, local_assigns = nil, status = nil) #:doc: 57 add_variables_to_assigns 58 render_text(@template.render_partial(partial_path, object, local_assigns), status) 50 59 end 51 60 52 61 # Renders a collection of partials using <tt>partial_name</tt> to iterate over the +collection+. 53 def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = {})#:doc: 54 render :partial => partial_name, :collection => collection, :spacer_template => partial_spacer_template, :locals => local_assigns 62 def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = nil, status = nil)#:doc: 63 add_variables_to_assigns 64 render_text(@template.render_partial_collection(partial_name, collection, partial_spacer_template, local_assigns), status) 55 65 end 56 66 branches/performance/actionpack/lib/action_controller/layout.rb
r1377 r1588 203 203 end 204 204 205 def render_with_a_layout(options = {}, deprecated_status = nil, deprecated_layout = nil) #:nodoc:205 def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil) #:nodoc: 206 206 options = render_with_a_layout_options(options) 207 207 if (layout = pick_layout(options, deprecated_layout)) 208 logger.info("Rendering #{options[:template]} within #{layout}") if logger 209 210 @content_for_layout = render_with_no_layout(options.merge(:layout => false)) 208 logger.info("Rendering #{options} within #{layout}") if logger 209 210 unless options 211 @content_for_layout = render_with_no_layout() 212 else 213 @content_for_layout = render_with_no_layout(options.merge(:layout => false)) 214 deprecated_status = options[:status] || deprecated_status 215 end 211 216 erase_render_results 212 217 213 @assigns[ 'content_for_layout'] = @content_for_layout214 render_text(@template.render_file(layout, true), options[:status] ||deprecated_status)218 @assigns["content_for_layout"] = @content_for_layout 219 render_text(@template.render_file(layout, true), deprecated_status) 215 220 else 216 221 render_with_no_layout(options, deprecated_status) … … 220 225 private 221 226 def render_with_a_layout_options(options) 222 return options unless options.is_a?(Hash) 223 case 224 when options[:text], options[:partial], options[:nothing], options[:inline] 225 # by default, :text, :partial, :inline, and :nothing never use a layout 226 { :layout => false }.merge(options) 227 else 228 options 229 end 230 end 231 232 def pick_layout(options = {}, deprecated_layout = nil) 227 if options.is_a?(Hash) 228 case 229 when options[:text], options[:partial], options[:inline], options[:nothing] 230 # by default, :text, :partial, :inline, and :nothing never use a layout 231 options = options.clone 232 options[:layout] = false 233 end 234 end 235 options 236 end 237 238 def pick_layout(options = nil, deprecated_layout = nil) 233 239 return deprecated_layout if !deprecated_layout.nil? 234 240 … … 248 254 249 255 def action_has_layout? 250 conditions = self.class.layout_conditions || {}251 case252 when conditions[:only]253 conditions[:only].include?(action_name)254 when conditions[:except]255 ! conditions[:except].include?(action_name)256 if conditions = self.class.layout_conditions 257 case 258 when only = conditions[:only] 259 only.include?(action_name) 260 when except = conditions[:except] 261 !except.include?(action_name) 256 262 else 257 263 true 264 end 265 else 266 true 258 267 end 259 268 end branches/performance/actionpack/lib/action_view/partials.rb
r1302 r1588 43 43 # This will render the partial "advertisement/_ad.rhtml" regardless of which controller this is being called from. 44 44 module Partials 45 def render_partial(partial_path, local_assigns = {}, deprecated_local_assigns = {})45 def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) 46 46 path, partial_name = partial_pieces(partial_path) 47 47 object = extracting_object(partial_name, local_assigns, deprecated_local_assigns) 48 48 local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns) 49 local_assigns = local_assigns ? local_assigns.clone : {} 49 50 add_counter_to_local_assigns!(partial_name, local_assigns) 51 local_assigns[partial_name] = object 50 52 51 render("#{path}/_#{partial_name}", { partial_name => object }.merge(local_assigns))53 render("#{path}/_#{partial_name}", local_assigns) 52 54 end 53 55 54 def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = {})56 def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = nil) 55 57 collection_of_partials = Array.new 56 58 counter_name = partial_counter_name(partial_name) 59 local_assigns = local_assigns ? local_assigns.clone : {} 57 60 collection.each_with_index do |element, counter| 58 collection_of_partials.push(render_partial(partial_name, element, { counter_name => counter }.merge(local_assigns))) 61 local_assigns[counter_name] = counter 62 collection_of_partials.push(render_partial(partial_name, element, local_assigns)) 59 63 end 60 64