2008-07-12 15:33:46 -04:00
|
|
|
module ActionView #:nodoc:
|
2008-08-21 01:28:25 -04:00
|
|
|
class PathSet < Array #:nodoc:
|
2009-10-08 21:12:28 -04:00
|
|
|
def self.type_cast(obj, cache = nil)
|
|
|
|
# TODO: Clean this up
|
2008-07-12 16:31:50 -04:00
|
|
|
if obj.is_a?(String)
|
2009-10-08 21:12:28 -04:00
|
|
|
if cache.nil?
|
2009-12-02 23:01:01 -05:00
|
|
|
cache = !defined?(Rails.application) || Rails.application.config.cache_classes
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
2009-06-17 18:32:55 -04:00
|
|
|
FileSystemResolverWithFallback.new(obj, :cache => cache)
|
2008-07-12 16:31:50 -04:00
|
|
|
else
|
|
|
|
obj
|
|
|
|
end
|
2008-07-12 15:33:46 -04:00
|
|
|
end
|
|
|
|
|
2008-08-21 01:28:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
super(*args).map! { |obj| self.class.type_cast(obj) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def <<(obj)
|
|
|
|
super(self.class.type_cast(obj))
|
|
|
|
end
|
|
|
|
|
|
|
|
def concat(array)
|
|
|
|
super(array.map! { |obj| self.class.type_cast(obj) })
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert(index, obj)
|
|
|
|
super(index, self.class.type_cast(obj))
|
|
|
|
end
|
|
|
|
|
|
|
|
def push(*objs)
|
|
|
|
super(*objs.map { |obj| self.class.type_cast(obj) })
|
|
|
|
end
|
|
|
|
|
|
|
|
def unshift(*objs)
|
|
|
|
super(*objs.map { |obj| self.class.type_cast(obj) })
|
|
|
|
end
|
|
|
|
|
2009-08-07 14:00:12 -04:00
|
|
|
def find(path, details = {}, prefix = nil, partial = false)
|
2009-04-23 18:58:38 -04:00
|
|
|
template_path = path
|
2009-01-22 17:18:10 -05:00
|
|
|
|
|
|
|
each do |load_path|
|
2009-08-07 14:00:12 -04:00
|
|
|
if template = load_path.find(template_path, details, prefix, partial)
|
2009-01-22 17:18:10 -05:00
|
|
|
return template
|
|
|
|
end
|
|
|
|
end
|
2009-04-23 18:58:38 -04:00
|
|
|
|
|
|
|
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path} - #{details.inspect} - partial: #{!!partial}")
|
2009-01-22 17:18:10 -05:00
|
|
|
end
|
2009-03-23 21:06:47 -04:00
|
|
|
|
2009-08-07 14:00:12 -04:00
|
|
|
def exists?(path, extension = nil, prefix = nil, partial = false)
|
2009-03-23 21:06:47 -04:00
|
|
|
template_path = path.sub(/^\//, '')
|
|
|
|
|
|
|
|
each do |load_path|
|
2009-08-07 14:00:12 -04:00
|
|
|
return true if template = load_path.find(template_path, extension, prefix, partial)
|
2009-03-23 21:06:47 -04:00
|
|
|
end
|
|
|
|
false
|
|
|
|
end
|
2009-01-22 17:18:10 -05:00
|
|
|
|
2009-02-24 11:38:07 -05:00
|
|
|
def find_template(original_template_path, format = nil, html_fallback = true)
|
2008-12-21 18:23:53 -05:00
|
|
|
return original_template_path if original_template_path.respond_to?(:render)
|
|
|
|
template_path = original_template_path.sub(/^\//, '')
|
2008-11-28 12:18:28 -05:00
|
|
|
|
2008-12-21 18:23:53 -05:00
|
|
|
each do |load_path|
|
2009-08-07 14:00:12 -04:00
|
|
|
if template = load_path.find(template_path, format)
|
2008-11-28 12:18:28 -05:00
|
|
|
return template
|
2009-01-27 15:09:11 -05:00
|
|
|
# Try to find html version if the format is javascript
|
2009-02-24 11:38:07 -05:00
|
|
|
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
|
2009-02-07 12:37:02 -05:00
|
|
|
return template
|
2009-02-24 11:38:07 -05:00
|
|
|
elsif format == :js && html_fallback && template = load_path["#{template_path}.html"]
|
2009-01-27 15:09:11 -05:00
|
|
|
return template
|
2008-11-28 12:18:28 -05:00
|
|
|
end
|
|
|
|
end
|
2008-12-21 18:23:53 -05:00
|
|
|
|
2009-04-13 18:18:45 -04:00
|
|
|
return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
|
2009-02-09 15:20:30 -05:00
|
|
|
|
2009-02-12 13:35:14 -05:00
|
|
|
raise MissingTemplate.new(self, original_template_path, format)
|
2008-11-28 12:18:28 -05:00
|
|
|
end
|
2008-07-12 15:33:46 -04:00
|
|
|
end
|
|
|
|
end
|