Changeset 3423
- Timestamp:
- 01/15/06 11:28:55 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/layout.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/layout_test.rb (modified) (2 diffs)
- trunk/actionpack/test/fixtures/layout_tests/layouts/controller_name_space (added)
- trunk/actionpack/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3412 r3423 1 1 *SVN* 2 3 * Automatically discover layouts when a controller is namespaced. #2199, #3424 [me@jonnii.com rails@jeffcole.net Marcel Molina Jr.] 2 4 3 5 * Add support for multiple proxy servers to CgiRequest#host [gaetanot@comcast.net] trunk/actionpack/lib/action_controller/layout.rb
r3397 r3423 175 175 def inherited(child) 176 176 inherited_without_layout(child) 177 child.layout(child.controller_name) unless layout_list.grep(/^#{child.controller_name}\.[a-z][0-9a-z]*$/).empty? 177 layout_match = child.name.underscore.sub(/_controller$/, '') 178 child.layout(layout_match) unless layout_list.grep(%r{layouts/#{layout_match}\.[a-z][0-9a-z]*$}).empty? 178 179 end 179 180 180 181 def layout_list 181 Dir.glob("#{template_root}/layouts/* .*").map { |layout| File.basename(layout) }182 Dir.glob("#{template_root}/layouts/**/*") 182 183 end 183 184 … … 203 204 when String then layout 204 205 end 205 206 active_layout.include?("/") ? active_layout : "layouts/#{active_layout}" if active_layout 206 207 # Explicitly passed layout names with slashes are looked up relative to the template root, 208 # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative 209 # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from. 210 nested_controller = File.directory?(File.dirname(File.join(self.class.template_root, 'layouts', active_layout))) 211 active_layout.include?('/') && !nested_controller ? active_layout : "layouts/#{active_layout}" if active_layout 207 212 end 208 213 trunk/actionpack/test/controller/layout_test.rb
r3397 r3423 19 19 20 20 class ThirdPartyTemplateLibraryController < LayoutTest 21 end 22 23 module ControllerNameSpace 24 end 25 26 class ControllerNameSpace::NestedController < LayoutTest 21 27 end 22 28 … … 58 64 assert_equal 'Mab', @response.body 59 65 end 66 67 def test_namespaced_controllers_auto_detect_layouts 68 @controller = ControllerNameSpace::NestedController.new 69 get :hello 70 assert_equal 'layouts/controller_name_space/nested', @controller.active_layout 71 assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body 72 end 60 73 61 74 end