diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-08 16:37:56 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-08 16:39:06 +0100 |
commit | 239262fee03096d1e52acf8fe69de736726d87e0 (patch) | |
tree | 45ae35ad20f86496328678ddbcc99580e3f2602d /actionpack/lib/action_view | |
parent | efc28a7f701e518eb747c57712f6c1d8e7027aeb (diff) | |
download | rails-239262fee03096d1e52acf8fe69de736726d87e0.tar.gz rails-239262fee03096d1e52acf8fe69de736726d87e0.tar.bz2 rails-239262fee03096d1e52acf8fe69de736726d87e0.zip |
Optimize layout lookup to avoid double calls.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/lookup_context.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderer/template_renderer.rb | 21 |
2 files changed, 14 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index d26158cefe..f586708d54 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -227,7 +227,6 @@ module ActionView end # A method which only uses the first format in the formats array for layout lookup. - # This method plays straight with instance variables for performance reasons. def with_layout_format if formats.size == 1 yield diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb index ac91d333ba..6bf91de05a 100644 --- a/actionpack/lib/action_view/renderer/template_renderer.rb +++ b/actionpack/lib/action_view/renderer/template_renderer.rb @@ -58,14 +58,21 @@ module ActionView # context object. If no layout is found, it checks if at least a layout with # the given name exists across all details before raising the error. def find_layout(layout, keys) - begin - with_layout_format do - layout =~ /^\// ? - with_fallbacks { find_template(layout, nil, false, keys, @details) } : find_template(layout, nil, false, keys, @details) + with_layout_format { resolve_layout(layout, keys) } + end + + def resolve_layout(layout, keys) + case layout + when String + if layout =~ /^\// + with_fallbacks { find_template(layout, nil, false, keys, @details) } + else + find_template(layout, nil, false, keys, @details) end - rescue ActionView::MissingTemplate - all_details = @details.merge(:formats => @lookup_context.default_formats) - raise unless template_exists?(layout, nil, false, keys, all_details) + when Proc + resolve_layout(layout.call, keys) + else + layout end end end |