Changeset 8214
- Timestamp:
- 11/26/07 03:59:23 (11 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (4 diffs)
- trunk/actionpack/lib/action_view/base.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/view_paths_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8213 r8214 1 1 *SVN* 2 3 * Add #prepend_view_path and #append_view_path instance methods on ActionController::Base for consistency with the class methods. [rick] 2 4 3 5 * Refactor sanitizer helpers into HTML classes and make it easy to swap them out with custom implementations. Closes #10129. [rick] trunk/actionpack/lib/action_controller/base.rb
r8189 r8214 431 431 # Adds a view_path to the front of the view_paths array. 432 432 # If the current class has no view paths, copy them from 433 # the superclass 433 # the superclass. This change will be visible for all future requests. 434 434 # 435 435 # ArticleController.prepend_view_path("views/default") … … 443 443 # Adds a view_path to the end of the view_paths array. 444 444 # If the current class has no view paths, copy them from 445 # the superclass 445 # the superclass. This change will be visible for all future requests. 446 446 # 447 447 # ArticleController.append_view_path("views/default") … … 637 637 end 638 638 639 640 639 self.view_paths = [] 641 640 … … 648 647 (@template || self.class).view_paths = value 649 648 end 649 650 # Adds a view_path to the front of the view_paths array. 651 # This change affects the current request only. 652 # 653 # self.prepend_view_path("views/default") 654 # self.prepend_view_path(["views/default", "views/custom"]) 655 # 656 def prepend_view_path(path) 657 (@template || self.class).prepend_view_path(path) 658 end 650 659 660 # Adds a view_path to the end of the view_paths array. 661 # This change affects the current request only. 662 # 663 # self.append_view_path("views/default") 664 # self.append_view_path(["views/default", "views/custom"]) 665 # 666 def append_view_path(path) 667 (@template || self.class).append_view_path(path) 668 end 669 651 670 protected 652 671 # Renders the content that will be returned to the browser as the response body. trunk/actionpack/lib/action_view/base.rb
r8211 r8214 266 266 267 267 def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc: 268 @view_paths = view_paths.respond_to?(:find) ? view_paths : [*view_paths].compact268 @view_paths = view_paths.respond_to?(:find) ? view_paths.dup : [*view_paths].compact 269 269 @assigns = assigns_for_first_render 270 270 @assigns_added = nil … … 471 471 def template_handler_preferences 472 472 TEMPLATE_HANDLER_PREFERENCES[template_format] || DEFAULT_TEMPLATE_HANDLER_PREFERENCE 473 end 474 475 # Adds a view_path to the front of the view_paths array. 476 # This change affects the current request only. 477 # 478 # @template.prepend_view_path("views/default") 479 # @template.prepend_view_path(["views/default", "views/custom"]) 480 # 481 def prepend_view_path(path) 482 @view_paths.unshift(*path) 483 end 484 485 # Adds a view_path to the end of the view_paths array. 486 # This change affects the current request only. 487 # 488 # @template.append_view_path("views/default") 489 # @template.append_view_path(["views/default", "views/custom"]) 490 # 491 def append_view_path(path) 492 @view_paths.push(*path) 473 493 end 474 494 trunk/actionpack/test/controller/view_paths_test.rb
r8135 r8214 48 48 end 49 49 50 def test_ template_appends_path_correctly50 def test_controller_appends_view_path_correctly 51 51 TestController.append_view_path 'foo' 52 52 assert_equal [LOAD_PATH_ROOT, 'foo'], @controller.view_paths … … 56 56 end 57 57 58 def test_ template_prepends_path_correctly58 def test_controller_prepends_view_path_correctly 59 59 TestController.prepend_view_path 'baz' 60 60 assert_equal ['baz', LOAD_PATH_ROOT], @controller.view_paths … … 62 62 TestController.prepend_view_path(%w(foo bar)) 63 63 assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths 64 end 65 66 def test_template_appends_view_path_correctly 67 @controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller) 68 class_view_paths = TestController.view_paths 69 70 @controller.append_view_path 'foo' 71 assert_equal [LOAD_PATH_ROOT, 'foo'], @controller.view_paths 72 73 @controller.append_view_path(%w(bar baz)) 74 assert_equal [LOAD_PATH_ROOT, 'foo', 'bar', 'baz'], @controller.view_paths 75 assert_equal class_view_paths, TestController.view_paths 76 end 77 78 def test_template_prepends_view_path_correctly 79 @controller.instance_variable_set :@template, ActionView::Base.new(TestController.view_paths, {}, @controller) 80 class_view_paths = TestController.view_paths 81 82 @controller.prepend_view_path 'baz' 83 assert_equal ['baz', LOAD_PATH_ROOT], @controller.view_paths 84 85 @controller.prepend_view_path(%w(foo bar)) 86 assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths 87 assert_equal class_view_paths, TestController.view_paths 64 88 end 65 89