fixture_template.rb 605 字节
Newer Older
Y
Yehuda Katz and Carl Lerche 已提交
1
module ActionView #:nodoc:
2
  class FixtureResolver < PathResolver
Y
Yehuda Katz + Carl Lerche 已提交
3 4 5 6
    def initialize(hash = {}, options = {})
      super(options)
      @hash = hash
    end
7

Y
Yehuda Katz + Carl Lerche 已提交
8
  private
9

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

16 17 18
      templates = []
      @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
        templates << Template.new(source, path, *path_to_details(path))
Y
Yehuda Katz + Carl Lerche 已提交
19
      end
20
      templates.sort_by {|t| -t.details.values.compact.size }
Y
Yehuda Katz and Carl Lerche 已提交
21
    end
22

Y
Yehuda Katz and Carl Lerche 已提交
23 24
  end
end