aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-15 11:39:22 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-15 11:39:22 +0000
commit17a74d90b667e6e14e3488c2e78ae75696857cf8 (patch)
tree68fd1192f51369f87e6b169c67b16fcc64627438
parent4d9cda5732538e9cdb325b2ffa7f9e97f8ac2ec0 (diff)
downloadrails-17a74d90b667e6e14e3488c2e78ae75696857cf8.tar.gz
rails-17a74d90b667e6e14e3488c2e78ae75696857cf8.tar.bz2
rails-17a74d90b667e6e14e3488c2e78ae75696857cf8.zip
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
-rw-r--r--actionpack/lib/action_controller/layout.rb16
1 files changed, 15 insertions, 1 deletions
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