Permalink
Browse files

A bunch of cleanup on the inherited template patch

  • Loading branch information...
wycats committed Dec 27, 2010
1 parent 6c5a3bb commit 7c568fda6ba2d6621a0872e4bc0c71bb2d13e65f
@@ -693,15 +693,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
end
def each_template(paths, name, &block) #:nodoc:
- Array.wrap(paths).each do |path|
- templates = lookup_context.find_all(name, path)
- templates = templates.uniq_by { |t| t.formats }
-
- unless templates.empty?
- templates.each(&block)
- return
- end
- end
+ templates = lookup_context.find_all(name, Array.wrap(paths))
+ templates.uniq_by { |t| t.formats }.each(&block)
end
def create_parts_from_responses(m, responses) #:nodoc:
@@ -201,7 +201,7 @@ def create_parts
if String === @body
@parts.unshift create_inline_part(@body)
elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ }
- lookup_context.find_all(@template, @mailer_name).each do |template|
+ lookup_context.find_all(@template, [@mailer_name]).each do |template|
self.formats = template.formats
@parts << create_inline_part(render(:template => template), template.mime_type)
end
@@ -11,23 +11,41 @@ def #{method}(*args)
end
def find(*args)
- template = find_all(*args).first
- template or raise MissingTemplate.new(self, "{#{args[1].join(',')},}/#{args[0]}", args[3], args[2])
+ if template = find_first(*args)
+ template
+ else
+ raise MissingTemplate.new(self, *args)
+ end
end
def find_all(path, prefixes = [], *args)
- templates = []
prefixes.each do |prefix|
+ templates = []
+
each do |resolver|
- templates << resolver.find_all(path, prefix, *args)
+ templates.concat resolver.find_all(path, prefix, *args)
end
- # return templates unless templates.flatten!.empty? XXX this was original behavior; turns this method into find_some, but probably makes it faster
+
+ return templates unless templates.empty?
end
- templates.flatten
+
+ []
+ 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
+ end
+ end
+
+ nil
end
def exists?(*args)
- find_all(*args).any?
+ !!find_first(*args)
end
protected
@@ -27,7 +27,7 @@ def message
class MissingTemplate < ActionViewError #:nodoc:
attr_reader :path
- def initialize(paths, path, details, partial)
+ def initialize(paths, path, prefixes, partial, details, *)
@path = path
display_paths = paths.compact.map{ |p| p.to_s.inspect }.join(", ")
template_type = if partial
@@ -38,7 +38,11 @@ def initialize(paths, path, details, partial)
'template'
end
- super("Missing #{template_type} #{path} with #{details.inspect} in view paths #{display_paths}")
+ searched_paths = prefixes.map { |prefix| [prefix, path].join("/") }
+
+ out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n"
+ out += paths.compact.map { |p| " * #{p.to_s.inspect}\n" }.join
+ super out
end
end
@@ -47,7 +47,7 @@ def build_path(name, prefix, partial)
path
end
- # Hnadles templates caching. If a key is given and caching is on
+ # Handles templates caching. If a key is given and caching is on
# always check the cache before hitting the resolver. Otherwise,
# it always hits the resolver but check if the resolver is fresher
# before returning it.
@@ -565,7 +565,7 @@ def using_resource_with_responder
def using_resource_with_action
respond_with(resource, :action => :foo) do |format|
- format.html { raise ActionView::MissingTemplate.new([], "foo/bar", {}, false) }
+ format.html { raise ActionView::MissingTemplate.new([], "bar", ["foo"], {}, false) }
end
end

0 comments on commit 7c568fd

Please sign in to comment.