fixture_template.rb 737 字节
Newer Older
Y
Yehuda Katz and Carl Lerche 已提交
1
module ActionView #:nodoc:
2
  class FixtureResolver < PathResolver
J
José Valim 已提交
3 4
    attr_reader :hash

J
José Valim 已提交
5 6
    def initialize(hash = {})
      super()
Y
Yehuda Katz + Carl Lerche 已提交
7 8
      @hash = hash
    end
9

Y
Yehuda Katz + Carl Lerche 已提交
10
  private
11

12
    def query(path, exts)
13 14
      query = Regexp.escape(path)
      exts.each do |ext|
15
        query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
Y
Yehuda Katz + Carl Lerche 已提交
16
      end
Y
Yehuda Katz + Carl Lerche 已提交
17

18 19
      templates = []
      @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
20 21
        handler, format = extract_handler_and_format(path)
        templates << Template.new(source, path, handler,
22
          :virtual_path => path, :format => format)
Y
Yehuda Katz + Carl Lerche 已提交
23
      end
24 25

      templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
Y
Yehuda Katz and Carl Lerche 已提交
26
    end
27

Y
Yehuda Katz and Carl Lerche 已提交
28 29
  end
end