Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 51 lines (40 sloc) 1.534 kB
91125f9 @dchelimsky move FixtureResolver to a file that is accessible outside Rails' own …
dchelimsky authored
1 require 'action_view/template/resolver'
2
a501638 @wycats Checkpoint
wycats authored
3 module ActionView #:nodoc:
91125f9 @dchelimsky move FixtureResolver to a file that is accessible outside Rails' own …
dchelimsky authored
4 # Use FixtureResolver in your tests to simulate the presence of files on the
5 # file system. This is used internally by Rails' own test suite, and is
6 # useful for testing extensions that have no way of knowing what the file
7 # system will look like at runtime.
f3fc5c4 Refactor ActionView::Resolver
Yehuda Katz + Carl Lerche authored
8 class FixtureResolver < PathResolver
6c02744 @josevalim Add tests for lookup context.
josevalim authored
9 attr_reader :hash
10
de1fe5e @nu7hatch [action_view] added custom patterns to template resolver
nu7hatch authored
11 def initialize(hash = {}, pattern=nil)
12 super(pattern)
8a4e77b OMG, a lot of work
Yehuda Katz + Carl Lerche authored
13 @hash = hash
14 end
1310231 @wycats Got tests to pass with some more changes.
wycats authored
15
ddd85ef @artemave #948 template_inheritance
artemave authored
16 def to_s
17 @hash.keys.join(', ')
18 end
19
20 private
1310231 @wycats Got tests to pass with some more changes.
wycats authored
21
f28d856 @josevalim Improve performance of the rendering stack by freezing formats as a s…
josevalim authored
22 def query(path, exts, formats)
c776080 @josevalim Allow cache to be temporarily disabled through lookup_context.
josevalim authored
23 query = ""
de1fe5e @nu7hatch [action_view] added custom patterns to template resolver
nu7hatch authored
24 EXTENSIONS.each do |ext|
25 query << '(' << exts[ext].map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
8a4e77b OMG, a lot of work
Yehuda Katz + Carl Lerche authored
26 end
c776080 @josevalim Allow cache to be temporarily disabled through lookup_context.
josevalim authored
27 query = /^(#{Regexp.escape(path)})#{query}$/
1b844e4 Passes in 1.9
Yehuda Katz + Carl Lerche authored
28
f3fc5c4 Refactor ActionView::Resolver
Yehuda Katz + Carl Lerche authored
29 templates = []
38d78f9 @josevalim Resolvers now consider timestamps.
josevalim authored
30 @hash.each do |_path, array|
31 source, updated_at = array
c776080 @josevalim Allow cache to be temporarily disabled through lookup_context.
josevalim authored
32 next unless _path =~ query
dafb4bd @miloops Don't shadow outer local variables.
miloops authored
33 handler, format = extract_handler_and_format(_path, formats)
34 templates << Template.new(source, _path, handler,
de1fe5e @nu7hatch [action_view] added custom patterns to template resolver
nu7hatch authored
35 :virtual_path => path.virtual, :format => format, :updated_at => updated_at)
8a4e77b OMG, a lot of work
Yehuda Katz + Carl Lerche authored
36 end
c2c8ef5 @guilleiguaran Remove trailing white-spaces
guilleiguaran authored
37
839362f @josevalim Make all AP tests pass for Ruby 1.9.1.
josevalim authored
38 templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
a501638 @wycats Checkpoint
wycats authored
39 end
40 end
8672a97 @dchelimsky add NullResolver
dchelimsky authored
41
243513f @josevalim Get rid of ruby warnings in Resolvers. Move a few methods up to the a…
josevalim authored
42 class NullResolver < PathResolver
8672a97 @dchelimsky add NullResolver
dchelimsky authored
43 def query(path, exts, formats)
44 handler, format = extract_handler_and_format(path, formats)
45 [ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)]
46 end
47 end
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
48
91125f9 @dchelimsky move FixtureResolver to a file that is accessible outside Rails' own …
dchelimsky authored
49 end
50
Something went wrong with that request. Please try again.