Changeset 6120
- Timestamp:
- 02/04/07 20:47:05 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/examples/address_book_controller.rb (modified) (1 diff)
- trunk/actionpack/examples/benchmark.rb (modified) (1 diff)
- trunk/actionpack/examples/blog_controller.cgi (modified) (1 diff)
- trunk/actionpack/examples/debate_controller.cgi (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (6 diffs)
- trunk/actionpack/lib/action_controller/layout.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_view/base.rb (modified) (8 diffs)
- trunk/actionpack/README (modified) (1 diff)
- trunk/actionpack/test/activerecord/pagination_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/action_pack_assertions_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/addresses_render_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/capture_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/content_type_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/layout_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/mime_responds_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/render_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/send_file_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/view_paths_test.rb (added)
- trunk/actionpack/test/fixtures/override (added)
- trunk/actionpack/test/fixtures/override/test (added)
- trunk/actionpack/test/fixtures/override/test/hello_world.rhtml (added)
- trunk/actionpack/test/template/deprecated_instance_variables_test.rb (modified) (1 diff)
- trunk/actionpack/test/template/url_helper_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6117 r6120 1 1 *SVN* 2 3 * Allow Controllers to have multiple view_paths instead of a single template_root. Closes #2754 [John Long] 2 4 3 5 * Add much-needed html-scanner tests. Fixed CDATA parsing bug. [Rick] trunk/actionpack/examples/address_book_controller.rb
r4715 r6120 43 43 end 44 44 45 ActionController::Base. template_root = File.dirname(__FILE__)45 ActionController::Base.view_paths = [ File.dirname(__FILE__) ] 46 46 # ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir 47 47 trunk/actionpack/examples/benchmark.rb
r4 r6120 25 25 end 26 26 27 #ActionController::Base. template_root = File.dirname(__FILE__)27 #ActionController::Base.view_paths = [ File.dirname(__FILE__) ] 28 28 29 29 require "benchmark" trunk/actionpack/examples/blog_controller.cgi
r4715 r6120 44 44 end 45 45 46 ActionController::Base. template_root = File.dirname(__FILE__)46 ActionController::Base.view_paths = [ File.dirname(__FILE__) ] 47 47 # ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir 48 48 trunk/actionpack/examples/debate_controller.cgi
r4715 r6120 48 48 end 49 49 50 ActionController::Base. template_root = File.dirname(__FILE__)50 ActionController::Base.view_paths = [ File.dirname(__FILE__) ] 51 51 # ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir 52 52 trunk/actionpack/lib/action_controller/base.rb
r5927 r6120 278 278 @@default_charset = "utf-8" 279 279 cattr_accessor :default_charset 280 281 # Template root determines the base from which template references will be made. So a call to render("test/template") 282 # will be converted to "#{template_root}/test/template.rhtml". 283 class_inheritable_accessor :template_root 284 280 285 281 # The logger is used for generating information on the action run-time (including benchmarking) if available. 286 282 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers. … … 358 354 write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect { |n| n.to_s }) 359 355 end 360 356 357 # Deprecated. Use view_paths instead. 358 def template_root=(path) 359 view_paths.unshift(path) 360 end 361 deprecate :template_root= => :view_paths 362 363 # Deprecated. Use view_paths instead. 364 def template_root 365 view_paths.first 366 end 367 deprecate :template_root => :view_paths 368 369 @@view_paths = {} 370 371 # View load paths determine the bases from which template references can be made. So a call to 372 # render("test/template") will be looked up in the view load paths array and the closest match will be 373 # returned. 374 def view_paths=(value) 375 @@view_paths[name] = value 376 end 377 378 # View load paths for controller. 379 def view_paths 380 if paths = @@view_paths[name] 381 paths 382 else 383 if superclass.respond_to?(:view_paths) 384 superclass.view_paths.dup.freeze 385 else 386 @@view_paths[name] = [] 387 end 388 end 389 end 390 361 391 # Replace sensitive paramater data from the request log. 362 392 # Filters paramaters that have any of the arguments as a substring. … … 535 565 self.class.controller_path 536 566 end 537 567 538 568 def session_enabled? 539 569 request.session_options[:disabled] != false 570 end 571 572 # View load paths for controller. 573 def view_paths 574 self.class.view_paths 540 575 end 541 576 … … 1031 1066 end 1032 1067 1033 def self.view_root1034 @view_root ||= template_root1035 end1036 1037 1068 def initialize_template_class(response) 1038 1069 raise "You must assign a template class through ActionController.template_class= before processing a request" unless @@template_class 1039 1070 1040 response.template = self.class.view_class.new( self.class.view_root, {}, self)1071 response.template = self.class.view_class.new(view_paths, {}, self) 1041 1072 response.redirected_to = nil 1042 1073 @performed_render = @performed_redirect = false … … 1057 1088 assign_deprecated_shortcuts(request, response) 1058 1089 end 1059 1060 1090 1061 1091 # TODO: assigns cookies headers params request response template … … 1152 1182 1153 1183 def add_class_variables_to_assigns 1154 %w( template_rootlogger template_class ignore_missing_templates).each do |cvar|1184 %w(view_paths logger template_class ignore_missing_templates).each do |cvar| 1155 1185 @assigns[cvar] = self.send(cvar) 1156 1186 end trunk/actionpack/lib/action_controller/layout.rb
r5813 r6120 180 180 @default_layout ||= read_inheritable_attribute("layout") 181 181 end 182 182 183 def layout_list #:nodoc: 184 view_paths.collect do |path| 185 Dir["#{path}/layouts/**/*"] 186 end.flatten 187 end 188 183 189 private 184 190 def inherited_with_layout(child) 185 191 inherited_without_layout(child) 186 192 layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '') 187 child.layout(layout_match) unless layout_list.grep(%r{layouts/#{layout_match}\.[a-z][0-9a-z]*$}).empty? 188 end 189 190 def layout_list 191 Dir.glob("#{template_root}/layouts/**/*") 193 child.layout(layout_match) unless child.layout_list.grep(%r{layouts/#{layout_match}\.[a-z][0-9a-z]*$}).empty? 192 194 end 193 195 … … 306 308 # we cache this info in a class level hash 307 309 def layout_directory?(layout_name) 308 template_path = File.join(self.class.view_root, 'layouts', layout_name) 310 view_paths.find do |path| 311 File.file?(File.join(path, 'layouts', layout_name)) 312 end 313 template_path ||= File.join(view_paths.first, 'layouts', layout_name) 309 314 dirname = File.dirname(template_path) 310 315 self.class.send(:layout_directory_exists_cache)[dirname] trunk/actionpack/lib/action_view/base.rb
r6057 r6120 233 233 end 234 234 235 def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil)#:nodoc: 236 @base_path, @assigns = base_path, assigns_for_first_render 235 def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc: 236 @view_paths = [*view_paths].compact 237 @assigns = assigns_for_first_render 237 238 @assigns_added = nil 238 239 @controller = controller … … 241 242 242 243 # Renders the template present at <tt>template_path</tt>. If <tt>use_full_path</tt> is set to true, 243 # it's relative to the template_root, otherwise it's absolute. The hash in <tt>local_assigns</tt>244 # it's relative to the view_paths array, otherwise it's absolute. The hash in <tt>local_assigns</tt> 244 245 # is made available as local variables. 245 246 def render_file(template_path, use_full_path = true, local_assigns = {}) #:nodoc: … … 269 270 raise e 270 271 else 271 raise TemplateError.new( @base_path, template_file_name, @assigns, template_source, e)272 end 273 end 274 end 275 276 # Renders the template present at <tt>template_path</tt> (relative to the template_root).272 raise TemplateError.new(find_base_path_for(template_file_name), template_file_name, @assigns, template_source, e) 273 end 274 end 275 end 276 277 # Renders the template present at <tt>template_path</tt> (relative to the view_paths array). 277 278 # The hash in <tt>local_assigns</tt> is made available as local variables. 278 279 def render(options = {}, old_local_assigns = {}, &block) #:nodoc: … … 359 360 def file_exists?(template_path)#:nodoc: 360 361 template_file_name, template_file_extension = path_and_extension(template_path) 361 362 362 if template_file_extension 363 363 template_exists?(template_file_name, template_file_extension) 364 364 else 365 365 cached_template_extension(template_path) || 366 %w(erb builder javascript delegate).any? do |template_type| 366 %w(erb builder javascript delegate).any? do |template_type| 367 367 send("#{template_type}_template_exists?", template_path) 368 368 end … … 377 377 private 378 378 def full_template_path(template_path, extension) 379 "#{@base_path}/#{template_path}.#{extension}" 379 file_name = "#{template_path}.#{extension}" 380 base_path = find_base_path_for(file_name) 381 "#{base_path}/#{file_name}" 380 382 end 381 383 … … 393 395 @@cache_template_extensions && @@cached_template_extension[template_path] 394 396 end 395 397 398 def find_base_path_for(template_file_name) 399 @view_paths.find { |p| File.file?(File.join(p, template_file_name)) } 400 end 401 396 402 def find_template_extension_for(template_path) 397 403 if match = delegate_template_exists?(template_path) … … 401 407 elsif javascript_template_exists?(template_path): :rjs 402 408 else 403 raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path} in #{@ base_path}"409 raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path} in #{@view_paths.inspect}" 404 410 end 405 411 end … … 537 543 end 538 544 539 raise TemplateError.new( @base_path, file_name || template, @assigns, template, e)545 raise TemplateError.new(lookup_template_base_path_for(file_name || template), file_name || template, @assigns, template, e) 540 546 end 541 547 trunk/actionpack/README
r4919 r6120 383 383 end 384 384 385 WeblogController::Base. template_root = File.dirname(__FILE__)385 WeblogController::Base.view_paths = [ File.dirname(__FILE__) ] 386 386 WeblogController.process_cgi if $0 == __FILE__ 387 387 trunk/actionpack/test/activerecord/pagination_test.rb
r4807 r6120 5 5 6 6 class PaginationController < ActionController::Base 7 self. template_root = "#{File.dirname(__FILE__)}/../fixtures/"7 self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ] 8 8 9 9 def simple_paginate trunk/actionpack/test/controller/action_pack_assertions_test.rb
r6055 r6120 153 153 # directory of test_request_response to simulate the behaviour of a 154 154 # production environment 155 ActionPackAssertionsController. template_root = File.dirname(__FILE__) + "/../fixtures/"155 ActionPackAssertionsController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 156 156 157 157 # a test case to exercise the new capabilities TestRequest & TestResponse trunk/actionpack/test/controller/addresses_render_test.rb
r4973 r6120 23 23 end 24 24 25 AddressesTestController. template_root = File.dirname(__FILE__) + "/../fixtures/"25 AddressesTestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 26 26 27 27 class AddressesTest < Test::Unit::TestCase trunk/actionpack/test/controller/capture_test.rb
r5501 r6120 24 24 end 25 25 26 CaptureController. template_root = File.dirname(__FILE__) + "/../fixtures/"26 CaptureController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 27 27 28 28 class CaptureTest < Test::Unit::TestCase trunk/actionpack/test/controller/content_type_test.rb
r5143 r6120 46 46 end 47 47 48 ContentTypeController. template_root = File.dirname(__FILE__) + "/../fixtures/"48 ContentTypeController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 49 49 50 50 class ContentTypeTest < Test::Unit::TestCase trunk/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
r5757 r6120 22 22 end 23 23 24 Target. template_root = File.dirname(__FILE__) + "/../../fixtures"24 Target.view_paths = [ File.dirname(__FILE__) + "/../../fixtures" ] 25 25 26 26 def setup trunk/actionpack/test/controller/layout_test.rb
r5927 r6120 1 1 require File.dirname(__FILE__) + '/../abstract_unit' 2 2 3 # The template_root must be set on Base and not LayoutTest so that LayoutTest's inherited method has access to 4 # the template_root when looking for a layout 5 ActionController::Base.template_root = File.dirname(__FILE__) + '/../fixtures/layout_tests/' 3 # The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited 4 # method has access to the view_paths array when looking for a layout to automatically assign. 5 old_load_paths = ActionController::Base.view_paths 6 ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ] 6 7 7 8 class LayoutTest < ActionController::Base 8 9 def self.controller_path; 'views' end 10 self.view_paths = ActionController::Base.view_paths.dup 9 11 end 10 12 11 # Restore template root to be unset12 ActionController::Base. template_root = nil13 # Restore view_paths to previous value 14 ActionController::Base.view_paths = old_load_paths 13 15 14 16 class ProductController < LayoutTest trunk/actionpack/test/controller/mime_responds_test.rb
r5697 r6120 119 119 end 120 120 121 RespondToController. template_root = File.dirname(__FILE__) + "/../fixtures/"121 RespondToController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 122 122 123 123 class MimeControllerTest < Test::Unit::TestCase trunk/actionpack/test/controller/new_render_test.rb
r5893 r6120 351 351 end 352 352 353 NewRenderTestController. template_root = File.dirname(__FILE__) + "/../fixtures/"354 Fun::GamesController. template_root = File.dirname(__FILE__) + "/../fixtures/"353 NewRenderTestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 354 Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 355 355 356 356 class NewRenderTest < Test::Unit::TestCase trunk/actionpack/test/controller/render_test.rb
r5746 r6120 135 135 end 136 136 137 TestController. template_root = File.dirname(__FILE__) + "/../fixtures/"138 Fun::GamesController. template_root = File.dirname(__FILE__) + "/../fixtures/"137 TestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 138 Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 139 139 140 140 class RenderTest < Test::Unit::TestCase trunk/actionpack/test/controller/send_file_test.rb
r5626 r6120 22 22 end 23 23 24 SendFileController. template_root = File.dirname(__FILE__) + "/../fixtures/"24 SendFileController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] 25 25 26 26 class SendFileTest < Test::Unit::TestCase trunk/actionpack/test/template/deprecated_instance_variables_test.rb
r6057 r6120 3 3 class DeprecatedViewInstanceVariablesTest < Test::Unit::TestCase 4 4 class DeprecatedInstanceVariablesController < ActionController::Base 5 self. template_root = "#{File.dirname(__FILE__)}/../fixtures/"5 self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ] 6 6 7 7 def self.controller_path; 'deprecated_instance_variables' end trunk/actionpack/test/template/url_helper_test.rb
r6070 r6120 251 251 class UrlHelperWithControllerTest < Test::Unit::TestCase 252 252 class UrlHelperController < ActionController::Base 253 self. template_root = "#{File.dirname(__FILE__)}/../fixtures/"253 self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ] 254 254 255 255 def self.controller_path; 'url_helper_with_controller' end … … 306 306 class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase 307 307 class TasksController < ActionController::Base 308 self. template_root = "#{File.dirname(__FILE__)}/../fixtures/"308 self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"] 309 309 310 310 def self.controller_path; 'tasks' end