From 51a7d9acdd4a01fb23e21be7a89e6440e51715e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 27 Dec 2010 09:14:13 +0100 Subject: Final tidy up on templates inheritance. --- actionpack/CHANGELOG | 6 ++++-- actionpack/lib/action_view/lookup_context.rb | 13 +++++++------ actionpack/lib/action_view/path_set.rb | 9 ++------- actionpack/lib/action_view/renderer/partial_renderer.rb | 2 +- actionpack/lib/action_view/renderer/template_renderer.rb | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 93b29bcc3a..20b19909fc 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,8 +1,10 @@ *Rails 3.1.0 (unreleased)* -* brought back config.action_view.cache_template_loading, which allows to decide whether templates should be cached or not [Piotr Sarnacki] +* Template lookup now searches further up in the inheritance chain. [Artemave] -* url_for and named url helpers now accept :subdomain and :domain as options [Josh Kalderimis] +* Brought back config.action_view.cache_template_loading, which allows to decide whether templates should be cached or not. [Piotr Sarnacki] + +* url_for and named url helpers now accept :subdomain and :domain as options, [Josh Kalderimis] * The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused (check the documentation for examples). [Josh Kalderimis] diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 0d7f15e564..1365048724 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -119,13 +119,14 @@ module ActionView name = name.to_s.gsub(handlers_regexp, '') parts = name.split('/') name = parts.pop - prx = if prefixes.blank? - [parts.compact.join('/')] - else - prefixes.map {|prefix| [prefix, *parts].compact.join('/') } - end - return name, prx + prefixes = if prefixes.blank? + [parts.join('/')] + else + prefixes.map { |prefix| [prefix, *parts].compact.join('/') } + end + + return name, prefixes end def default_handlers #:nodoc: diff --git a/actionpack/lib/action_view/path_set.rb b/actionpack/lib/action_view/path_set.rb index 2a54b12f78..2f662b0739 100644 --- a/actionpack/lib/action_view/path_set.rb +++ b/actionpack/lib/action_view/path_set.rb @@ -21,26 +21,21 @@ module ActionView #:nodoc: def find_all(path, prefixes = [], *args) prefixes.each do |prefix| templates = [] - each do |resolver| templates.concat resolver.find_all(path, prefix, *args) end - return templates unless templates.empty? end - [] end def find_first(path, prefixes = [], *args) prefixes.each do |prefix| each do |resolver| - if template = resolver.find_all(path, prefix, *args).first - return template - end + template = resolver.find_all(path, prefix, *args).first + return template if template end end - nil end diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index f36b0602b1..3fdea23a4a 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -111,7 +111,7 @@ module ActionView end def find_template(path=@path, locals=@locals.keys) - prefixes = path.include?(?/) ? [] : @view.controller._prefixes + prefixes = path.include?(?/) ? [] : @view.controller_prefixes @lookup_context.find_template(path, prefixes, true, locals) end diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb index 938bb2a3f3..9ae1636131 100644 --- a/actionpack/lib/action_view/renderer/template_renderer.rb +++ b/actionpack/lib/action_view/renderer/template_renderer.rb @@ -43,7 +43,7 @@ module ActionView if options.key?(:text) Template::Text.new(options[:text], formats.try(:first)) elsif options.key?(:file) - with_fallbacks { find_template(options[:file], [], false, keys) } + with_fallbacks { find_template(options[:file], options[:prefixes], false, keys) } elsif options.key?(:inline) handler = Template.handler_for_extension(options[:type] || "erb") Template.new(options[:inline], "inline template", handler, :locals => keys) -- cgit v1.2.3