From 17a74d90b667e6e14e3488c2e78ae75696857cf8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 15 Dec 2004 11:39:22 +0000 Subject: Added that controllers will now search for a layout in $template_root/layouts/$controller_name.r(html|xml), so PostsController will look for layouts/posts.rhtml or layouts/posts.rxml and automatically configure this layout if found #307 [Marcel] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/layout.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 7ae25ddabd..25c0afd83b 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -2,11 +2,14 @@ module ActionController #:nodoc: module Layout #:nodoc: def self.append_features(base) super - base.extend(ClassMethods) base.class_eval do alias_method :render_without_layout, :render alias_method :render, :render_with_layout + class << self + alias_method :inherited_without_layout, :inherited + end end + base.extend(ClassMethods) end # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in @@ -119,6 +122,16 @@ module ActionController #:nodoc: def layout(template_name) write_inheritable_attribute "layout", template_name end + + private + def inherited(child) + inherited_without_layout(child) + child.layout(child.controller_name) unless layout_list.grep(/^#{child.controller_name}\.r(?:xml|html)$/).empty? + end + + def layout_list + Dir.glob("#{template_root}/layouts/*.r{xml,html}").map { |layout| File.basename(layout) } + end end # Returns the name of the active layout. If the layout was specified as a method reference (through a symbol), this method @@ -145,5 +158,6 @@ module ActionController #:nodoc: render_without_layout(template_name, status) end end + end end -- cgit v1.2.3