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
This commit is contained in:
David Heinemeier Hansson 2004-12-15 11:39:22 +00:00
parent 4d9cda5732
commit 17a74d90b6
1 changed files with 15 additions and 1 deletions

View File

@ -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