diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index e5886b724d..3df107c639 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -122,21 +122,29 @@ module ActionView attr_reader :view_paths, :html_fallback_for_js def find(name, prefixes = [], partial = false, keys = [], options = {}) - @view_paths.find(*args_for_lookup(name, prefixes, partial, keys, options)) + name, prefixes = normalize_name(name, prefixes) + details, details_key = detail_args_for(options) + @view_paths.find(name, prefixes, partial, details, details_key, keys) end alias :find_template :find def find_all(name, prefixes = [], partial = false, keys = [], options = {}) - @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options)) + name, prefixes = normalize_name(name, prefixes) + details, details_key = detail_args_for(options) + @view_paths.find_all(name, prefixes, partial, details, details_key, keys) end def exists?(name, prefixes = [], partial = false, keys = [], **options) - @view_paths.exists?(*args_for_lookup(name, prefixes, partial, keys, options)) + name, prefixes = normalize_name(name, prefixes) + details, details_key = detail_args_for(options) + @view_paths.exists?(name, prefixes, partial, details, details_key, keys) end alias :template_exists? :exists? def any?(name, prefixes = [], partial = false) - @view_paths.exists?(*args_for_any(name, prefixes, partial)) + name, prefixes = normalize_name(name, prefixes) + details, details_key = detail_args_for_any + @view_paths.exists?(name, prefixes, partial, details, details_key, []) end alias :any_templates? :any? @@ -147,12 +155,6 @@ module ActionView ActionView::PathSet.new(Array(paths)) end - def args_for_lookup(name, prefixes, partial, keys, details_options) - name, prefixes = normalize_name(name, prefixes) - details, details_key = detail_args_for(details_options) - [name, prefixes, partial || false, details, details_key, keys] - end - # Compute details hash and key according to user options (e.g. passed from #render). def detail_args_for(options) # :doc: return @details, details_key if options.empty? # most common path. @@ -167,12 +169,6 @@ module ActionView [user_details, details_key] end - def args_for_any(name, prefixes, partial) - name, prefixes = normalize_name(name, prefixes) - details, details_key = detail_args_for_any - [name, prefixes, partial || false, details, details_key] - end - def detail_args_for_any @detail_args_for_any ||= begin details = {} diff --git a/actionview/lib/action_view/path_set.rb b/actionview/lib/action_view/path_set.rb index 3e523ac9f1..3be4fd61fc 100644 --- a/actionview/lib/action_view/path_set.rb +++ b/actionview/lib/action_view/path_set.rb @@ -44,28 +44,31 @@ module ActionView #:nodoc: METHOD end - def find(*args) - find_all(*args).first || raise(MissingTemplate.new(self, *args)) + def find(path, prefixes, partial, details, details_key, locals) + find_all(path, prefixes, partial, details, details_key, locals).first || + raise(MissingTemplate.new(self, path, prefixes, partial, details, details_key, locals)) end - def find_all(path, prefixes = [], *args) - _find_all path, prefixes, args + def find_all(path, prefixes, partial, details, details_key, locals) + search_combinations(prefixes) do |resolver, prefix| + templates = resolver.find_all(path, prefix, partial, details, details_key, locals) + return templates unless templates.empty? + end + [] end - def exists?(path, prefixes, *args) - find_all(path, prefixes, *args).any? + def exists?(path, prefixes, partial, details, details_key, locals) + find_all(path, prefixes, partial, details, details_key, locals).any? end private - def _find_all(path, prefixes, args) + def search_combinations(prefixes) prefixes = Array(prefixes) prefixes.each do |prefix| paths.each do |resolver| - templates = resolver.find_all(path, prefix, *args) - return templates unless templates.empty? + yield resolver, prefix end end - [] end def typecast(paths) diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index ddf69f7930..c00f37a9d2 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -221,7 +221,7 @@ class TestMissingTemplate < ActiveSupport::TestCase test "if a single prefix is passed as a string and the lookup fails, MissingTemplate accepts it" do e = assert_raise ActionView::MissingTemplate do details = { handlers: [], formats: [], variants: [], locale: [] } - @lookup_context.view_paths.find("foo", "parent", true, details) + @lookup_context.view_paths.find("foo", "parent", true, details, nil, []) end assert_match %r{Missing partial parent/_foo with .*\n\nSearched in:\n \* "/Path/to/views"\n}, e.message end