2008-07-12 15:33:46 -04:00
|
|
|
module ActionView #:nodoc:
|
2008-08-21 01:28:25 -04:00
|
|
|
class PathSet < Array #:nodoc:
|
2010-03-07 06:49:27 -05:00
|
|
|
%w(initialize << concat insert push unshift).each do |method|
|
|
|
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
|
|
|
def #{method}(*args)
|
|
|
|
super
|
|
|
|
typecast!
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
2010-03-07 06:49:27 -05:00
|
|
|
METHOD
|
2008-08-21 01:28:25 -04:00
|
|
|
end
|
|
|
|
|
2010-03-08 17:13:24 -05:00
|
|
|
def find(path, prefix = nil, partial = false, details = {}, key = nil)
|
|
|
|
template = find_all(path, prefix, partial, details, key).first
|
|
|
|
raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template
|
|
|
|
template
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_all(*args)
|
2010-03-08 14:57:33 -05:00
|
|
|
each do |resolver|
|
2010-03-08 17:13:24 -05:00
|
|
|
templates = resolver.find_all(*args)
|
2010-03-08 14:57:33 -05:00
|
|
|
return templates unless templates.empty?
|
|
|
|
end
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2010-03-08 17:13:24 -05:00
|
|
|
def exists?(*args)
|
|
|
|
find_all(*args).any?
|
2009-03-23 21:06:47 -04:00
|
|
|
end
|
2009-01-22 17:18:10 -05:00
|
|
|
|
2010-03-07 06:49:27 -05:00
|
|
|
protected
|
2008-11-28 12:18:28 -05:00
|
|
|
|
2010-03-07 06:49:27 -05:00
|
|
|
def typecast!
|
|
|
|
each_with_index do |path, i|
|
2010-06-02 16:56:41 -04:00
|
|
|
path = path.to_s if path.is_a?(Pathname)
|
2010-03-07 06:49:27 -05:00
|
|
|
next unless path.is_a?(String)
|
2010-03-08 10:32:40 -05:00
|
|
|
self[i] = FileSystemResolver.new(path)
|
2008-11-28 12:18:28 -05:00
|
|
|
end
|
|
|
|
end
|
2008-07-12 15:33:46 -04:00
|
|
|
end
|
|
|
|
end
|