Skip to content
Browse files

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
  • Loading branch information...
1 parent 4d9cda5 commit 17a74d90b667e6e14e3488c2e78ae75696857cf8 @dhh dhh committed Dec 15, 2004
Showing with 15 additions and 1 deletion.
  1. +15 −1 actionpack/lib/action_controller/layout.rb
View
16 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 ClassMethods
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 @@ def render_with_layout(template_name = default_template_name, status = nil, layo
render_without_layout(template_name, status)
end
end
+
end
end

0 comments on commit 17a74d9

Please sign in to comment.
Something went wrong with that request. Please try again.