Changeset 6403
- Timestamp:
- 03/13/07 04:46:12 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/components.rb (modified) (6 diffs)
- trunk/actionpack/test/controller/components_test.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6402 r6403 1 1 *SVN* 2 2 3 * Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. [Jeremy Kemper]3 * Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. [Jeremy Kemper] 4 4 5 5 * Consistent public/protected/private visibility for chained methods. #7813 [Dan Manges] trunk/actionpack/lib/action_controller/components.rb
r6125 r6403 18 18 # 19 19 # The same can be done in a view to do a partial rendering: 20 # 21 # Let's see a greeting: 20 # 21 # Let's see a greeting: 22 22 # <%= render_component :controller => "greeter", :action => "hello_world" %> 23 23 # 24 24 # It is also possible to specify the controller as a class constant, bypassing the inflector 25 25 # code to compute the controller class at runtime: 26 # 26 # 27 27 # <%= render_component :controller => GreeterController, :action => "hello_world" %> 28 28 # … … 31 31 # Components should be used with care. They're significantly slower than simply splitting reusable parts into partials and 32 32 # conceptually more complicated. Don't use components as a way of separating concerns inside a single application. Instead, 33 # reserve components to those rare cases where you truly have reusable view and controller elements that can be employed 33 # reserve components to those rare cases where you truly have reusable view and controller elements that can be employed 34 34 # across many applications at once. 35 35 # … … 41 41 42 42 base.helper do 43 def render_component(options) 43 def render_component(options) 44 44 @controller.send(:render_component_as_string, options) 45 45 end 46 46 end 47 47 48 48 # If this controller was instantiated to process a component request, 49 49 # +parent_controller+ points to the instantiator of this controller. 50 50 base.send :attr_accessor, :parent_controller 51 51 52 52 base.class_eval do 53 53 alias_method_chain :process_cleanup, :components … … 55 55 alias_method_chain :flash, :components 56 56 57 alias_method :component_request?, :parent_controller 57 alias_method :component_request?, :parent_controller 58 58 end 59 59 end … … 66 66 controller.process(request, response) 67 67 end 68 69 # Set the template root to be one directory behind the root dir of the controller. Examples:70 # /code/weblog/components/admin/users_controller.rb with Admin::UsersController71 # will use /code/weblog/components as template root72 # and find templates in /code/weblog/components/admin/users/73 #74 # /code/weblog/components/admin/parties/users_controller.rb with Admin::Parties::UsersController75 # will also use /code/weblog/components as template root76 # and find templates in /code/weblog/components/admin/parties/users/77 def uses_component_template_root78 path_of_calling_controller = File.dirname(caller[1].split(/:\d+:/, 2).first)79 path_of_controller_root = path_of_calling_controller.sub(/#{Regexp.escape(File.dirname(controller_path))}$/, "")80 prepend_view_path path_of_controller_root81 view_paths.first82 end83 84 deprecate :uses_component_template_root => 'Components are deprecated and will be removed in Rails 2.0.'85 68 end 86 69 … … 91 74 process_without_components(request, response, method, *arguments) 92 75 end 93 76 94 77 protected 95 78 # Renders the component specified as the response for the current method trunk/actionpack/test/controller/components_test.rb
r5631 r6403 21 21 render_template "Are you there? <%= render_component(:action => 'internal_callee') %>" 22 22 end 23 23 24 24 def internal_callee 25 25 render_text "Yes, ma'am" … … 33 33 render_component(:controller => "callee", :action => "use_flash") 34 34 end 35 35 36 36 def calling_redirected 37 37 render_component(:controller => "callee", :action => "redirected") 38 38 end 39 39 40 40 def calling_redirected_as_string 41 41 render_template "<%= render_component(:controller => 'callee', :action => 'redirected') %>" … … 49 49 render_text "#{params[:name] || "Lady"} of the House, speaking" 50 50 end 51 51 52 52 def blowing_up 53 53 render_text "It's game over, man, just game over, man!", "500 Internal Server Error" 54 54 end 55 55 56 56 def set_flash 57 57 flash[:notice] = 'My stoney baby' 58 58 render :text => 'flash is set' 59 59 end 60 60 61 61 def use_flash 62 62 render :text => flash[:notice] || 'no flash' 63 63 end 64 64 65 65 def redirected 66 66 redirect_to :controller => "callee", :action => "being_called" … … 86 86 assert_equal "David of the House, speaking", @response.body 87 87 end 88 88 89 89 def test_calling_from_controller_with_different_status_code 90 90 get :calling_from_controller_with_different_status_code … … 96 96 assert_equal "Ring, ring: Lady of the House, speaking", @response.body 97 97 end 98 98 99 99 def test_internal_calling 100 100 get :internal_caller 101 101 assert_equal "Are you there? Yes, ma'am", @response.body 102 102 end 103 103 104 104 def test_flash 105 105 get :set_flash … … 110 110 assert_equal 'no flash', @response.body 111 111 end 112 112 113 113 def test_component_redirect_redirects 114 114 get :calling_redirected 115 115 116 116 assert_redirected_to :action => "being_called" 117 117 end 118 118 119 119 def test_component_multiple_redirect_redirects 120 120 test_component_redirect_redirects 121 121 test_internal_calling 122 122 end 123 123 124 124 def test_component_as_string_redirect_renders_redirecte_action 125 125 get :calling_redirected_as_string 126 126 127 127 assert_equal "Lady of the House, speaking", @response.body 128 128 end 129 129 end 130 131 module A132 module B133 module C134 class NestedController < ActionController::Base135 # Stub for uses_component_template_root136 def self.caller137 [ '/path/to/active_support/deprecation.rb:93:in `uses_component_template_root',138 './test/fixtures/a/b/c/nested_controller.rb' ]139 end140 end141 end142 end143 end144 145 class UsesComponentTemplateRootTest < Test::Unit::TestCase146 def test_uses_component_template_root147 assert_deprecated 'uses_component_template_root' do148 assert_equal './test/fixtures/', A::B::C::NestedController.uses_component_template_root149 end150 end151 end