Updated README.rdoc again
[feedcatcher.git] / vendor / rails / actionpack / lib / action_view / paths.rb
1 module ActionView #:nodoc:
2 class PathSet < Array #:nodoc:
3 def self.type_cast(obj)
4 if obj.is_a?(String)
5 if Base.cache_template_loading?
6 Template::EagerPath.new(obj.to_s)
7 else
8 ReloadableTemplate::ReloadablePath.new(obj.to_s)
9 end
10 else
11 obj
12 end
13 end
14
15 def initialize(*args)
16 super(*args).map! { |obj| self.class.type_cast(obj) }
17 end
18
19 def <<(obj)
20 super(self.class.type_cast(obj))
21 end
22
23 def concat(array)
24 super(array.map! { |obj| self.class.type_cast(obj) })
25 end
26
27 def insert(index, obj)
28 super(index, self.class.type_cast(obj))
29 end
30
31 def push(*objs)
32 super(*objs.map { |obj| self.class.type_cast(obj) })
33 end
34
35 def unshift(*objs)
36 super(*objs.map { |obj| self.class.type_cast(obj) })
37 end
38
39 def load!
40 each(&:load!)
41 end
42
43 def find_template(original_template_path, format = nil, html_fallback = true)
44 return original_template_path if original_template_path.respond_to?(:render)
45 template_path = original_template_path.sub(/^\//, '')
46
47 each do |load_path|
48 if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"])
49 return template
50 elsif format && (template = load_path["#{template_path}.#{format}"])
51 return template
52 elsif template = load_path["#{template_path}.#{I18n.locale}"]
53 return template
54 elsif template = load_path[template_path]
55 return template
56 # Try to find html version if the format is javascript
57 elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
58 return template
59 elsif format == :js && html_fallback && template = load_path["#{template_path}.html"]
60 return template
61 end
62 end
63
64 return Template.new(original_template_path, original_template_path =~ /\A\// ? "" : ".") if File.file?(original_template_path)
65
66 raise MissingTemplate.new(self, original_template_path, format)
67 end
68 end
69 end