2008-10-27 07:47:01 +01:00
|
|
|
module ActionView #:nodoc:
|
|
|
|
class PathSet < Array #:nodoc:
|
|
|
|
def self.type_cast(obj)
|
|
|
|
if obj.is_a?(String)
|
2009-02-28 02:23:00 +01:00
|
|
|
if Base.cache_template_loading?
|
|
|
|
Template::EagerPath.new(obj.to_s)
|
|
|
|
else
|
|
|
|
ReloadableTemplate::ReloadablePath.new(obj.to_s)
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
else
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
end
|
2009-02-28 02:23:00 +01:00
|
|
|
|
2008-10-27 07:47:01 +01: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-02-28 02:23:00 +01:00
|
|
|
|
|
|
|
def load!
|
|
|
|
each(&:load!)
|
|
|
|
end
|
2008-10-27 07:47:01 +01:00
|
|
|
|
2009-02-28 02:23:00 +01:00
|
|
|
def find_template(original_template_path, format = nil, html_fallback = true)
|
2009-02-04 21:26:08 +01:00
|
|
|
return original_template_path if original_template_path.respond_to?(:render)
|
|
|
|
template_path = original_template_path.sub(/^\//, '')
|
2008-10-27 07:47:01 +01:00
|
|
|
|
2009-02-04 21:26:08 +01:00
|
|
|
each do |load_path|
|
|
|
|
if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"])
|
|
|
|
return template
|
|
|
|
elsif format && (template = load_path["#{template_path}.#{format}"])
|
|
|
|
return template
|
|
|
|
elsif template = load_path["#{template_path}.#{I18n.locale}"]
|
|
|
|
return template
|
|
|
|
elsif template = load_path[template_path]
|
|
|
|
return template
|
|
|
|
# Try to find html version if the format is javascript
|
2009-02-28 02:23:00 +01:00
|
|
|
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
|
|
|
|
return template
|
|
|
|
elsif format == :js && html_fallback && template = load_path["#{template_path}.html"]
|
2008-10-27 07:47:01 +01:00
|
|
|
return template
|
|
|
|
end
|
|
|
|
end
|
2009-02-04 21:26:08 +01:00
|
|
|
|
2009-03-16 15:55:30 +01:00
|
|
|
return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
|
2009-02-28 02:23:00 +01:00
|
|
|
|
|
|
|
raise MissingTemplate.new(self, original_template_path, format)
|
2008-10-27 07:47:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|