2010-05-02 10:20:17 -04:00
|
|
|
require 'action_view/template/resolver'
|
|
|
|
|
2009-03-23 18:45:01 -04:00
|
|
|
module ActionView #:nodoc:
|
2010-05-02 10:20:17 -04:00
|
|
|
# Use FixtureResolver in your tests to simulate the presence of files on the
|
|
|
|
# file system. This is used internally by Rails' own test suite, and is
|
|
|
|
# useful for testing extensions that have no way of knowing what the file
|
|
|
|
# system will look like at runtime.
|
2009-09-02 18:00:22 -04:00
|
|
|
class FixtureResolver < PathResolver
|
2010-03-11 06:45:05 -05:00
|
|
|
attr_reader :hash
|
|
|
|
|
2011-03-19 00:13:59 -04:00
|
|
|
def initialize(hash = {}, pattern=nil)
|
|
|
|
super(pattern)
|
2009-04-27 21:21:26 -04:00
|
|
|
@hash = hash
|
|
|
|
end
|
2009-08-15 01:32:40 -04:00
|
|
|
|
2010-09-17 16:39:14 -04:00
|
|
|
def to_s
|
|
|
|
@hash.keys.join(', ')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2009-08-15 01:32:40 -04:00
|
|
|
|
2010-03-19 12:20:15 -04:00
|
|
|
def query(path, exts, formats)
|
2010-10-07 15:30:19 -04:00
|
|
|
query = ""
|
2011-03-19 00:13:59 -04:00
|
|
|
EXTENSIONS.each do |ext|
|
|
|
|
query << '(' << exts[ext].map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2010-10-07 15:30:19 -04:00
|
|
|
query = /^(#{Regexp.escape(path)})#{query}$/
|
2009-06-23 17:45:27 -04:00
|
|
|
|
2009-09-02 18:00:22 -04:00
|
|
|
templates = []
|
2010-10-10 03:24:17 -04:00
|
|
|
@hash.each do |_path, array|
|
|
|
|
source, updated_at = array
|
2010-10-07 15:30:19 -04:00
|
|
|
next unless _path =~ query
|
2010-09-22 15:53:02 -04:00
|
|
|
handler, format = extract_handler_and_format(_path, formats)
|
|
|
|
templates << Template.new(source, _path, handler,
|
2011-03-19 00:13:59 -04:00
|
|
|
:virtual_path => path.virtual, :format => format, :updated_at => updated_at)
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2011-06-05 11:34:40 -04:00
|
|
|
|
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
|
|
|
|
end
|
2010-05-02 11:04:32 -04:00
|
|
|
|
2010-10-07 07:26:58 -04:00
|
|
|
class NullResolver < PathResolver
|
2010-05-02 11:04:32 -04:00
|
|
|
def query(path, exts, formats)
|
|
|
|
handler, format = extract_handler_and_format(path, formats)
|
|
|
|
[ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)]
|
|
|
|
end
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-05-02 10:20:17 -04:00
|
|
|
end
|
|
|
|
|