2009-03-23 18:45:01 -04:00
|
|
|
module ActionView #:nodoc:
|
2009-09-02 18:00:22 -04:00
|
|
|
class FixtureResolver < PathResolver
|
2010-03-11 06:45:05 -05:00
|
|
|
attr_reader :hash
|
|
|
|
|
2010-03-07 06:49:27 -05:00
|
|
|
def initialize(hash = {})
|
|
|
|
super()
|
2009-04-27 21:21:26 -04:00
|
|
|
@hash = hash
|
|
|
|
end
|
2009-08-15 01:32:40 -04:00
|
|
|
|
2009-04-27 21:21:26 -04:00
|
|
|
private
|
2009-08-15 01:32:40 -04:00
|
|
|
|
2010-03-18 07:10:40 -04:00
|
|
|
def query(path, exts)
|
2009-09-02 18:00:22 -04:00
|
|
|
query = Regexp.escape(path)
|
|
|
|
exts.each do |ext|
|
2010-03-15 21:08:34 -04:00
|
|
|
query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2009-06-23 17:45:27 -04:00
|
|
|
|
2009-09-02 18:00:22 -04:00
|
|
|
templates = []
|
|
|
|
@hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
|
2010-03-09 07:12:11 -05:00
|
|
|
handler, format = extract_handler_and_format(path)
|
|
|
|
templates << Template.new(source, path, handler,
|
2010-03-18 07:10:40 -04:00
|
|
|
:virtual_path => path, :format => format)
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2010-03-12 05:50:45 -05:00
|
|
|
|
|
|
|
templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
|
2009-03-23 18:45:01 -04:00
|
|
|
end
|
2009-09-02 18:00:22 -04:00
|
|
|
|
2009-03-23 18:45:01 -04:00
|
|
|
end
|
|
|
|
end
|