diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-02-22 23:52:02 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-02-22 23:52:02 +0100 |
commit | 21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd (patch) | |
tree | bfec5946303ceb582674904c5f9927e9b4020272 /actionpack/lib/action_controller/layout.rb | |
parent | 91ab75373f13054485f5d804d7e2c80d466ff5e0 (diff) | |
parent | 441e4e22352c8805a882f6a661ab3982dd7eda12 (diff) | |
download | rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.tar.gz rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.tar.bz2 rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/lib/action_controller/layout.rb')
-rw-r--r-- | actionpack/lib/action_controller/layout.rb | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index d6bcf7a8c1..a0db7acf72 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -172,23 +172,10 @@ module ActionController #:nodoc: @layout_conditions ||= read_inheritable_attribute(:layout_conditions) end - def default_layout(format) #:nodoc: - layout = read_inheritable_attribute(:layout) unless format == :js - return layout unless read_inheritable_attribute(:auto_layout) - find_layout(layout, format) - end - def layout_list #:nodoc: Array(view_paths).sum([]) { |path| Dir["#{path.to_str}/layouts/**/*"] } end - def find_layout(layout, *formats) #:nodoc: - return layout if layout.respond_to?(:render) - view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", *formats) - rescue ActionView::MissingTemplate - nil - end - private def inherited_with_layout(child) inherited_without_layout(child) @@ -212,35 +199,29 @@ module ActionController #:nodoc: # object). If the layout was defined without a directory, layouts is assumed. So <tt>layout "weblog/standard"</tt> will return # weblog/standard, but <tt>layout "standard"</tt> will return layouts/standard. def active_layout(passed_layout = nil) - layout = passed_layout || self.class.default_layout(default_template_format) + layout = passed_layout || default_layout + return layout if layout.respond_to?(:render) active_layout = case layout when Symbol then __send__(layout) when Proc then layout.call(self) else layout end - - if active_layout - if layout = self.class.find_layout(active_layout, @template.template_format) - layout - else - raise ActionView::MissingTemplate.new(self.class.view_paths, active_layout) - end - end + + find_layout(active_layout, @template.template_format) if active_layout end private - def candidate_for_layout?(options) - template = options[:template] || default_template(options[:action]) - if options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? - begin - !self.view_paths.find_template(template, default_template_format).exempt_from_layout? - rescue ActionView::MissingTemplate - true - end - end + def default_layout #:nodoc: + layout = self.class.read_inheritable_attribute(:layout) unless default_template_format == :js + return layout unless self.class.read_inheritable_attribute(:auto_layout) + find_layout(layout, default_template_format) rescue ActionView::MissingTemplate - false + nil + end + + def find_layout(layout, *formats) #:nodoc: + view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", *formats) end def pick_layout(options) @@ -273,6 +254,19 @@ module ActionController #:nodoc: end end + def candidate_for_layout?(options) + template = options[:template] || default_template(options[:action]) + if options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? + begin + !self.view_paths.find_template(template, default_template_format).exempt_from_layout? + rescue ActionView::MissingTemplate + true + end + end + rescue ActionView::MissingTemplate + false + end + def default_template_format response.template.template_format end |