aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/lib/fixture_template.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-09-08 15:38:51 -0300
committerEmilio Tagua <miloops@gmail.com>2009-09-08 15:38:51 -0300
commit670281c6b2e9b9e8c51a140f2a5f66b251f1b84b (patch)
treeab141872d72e010c8a0fe371d22a00914c97e1eb /actionpack/test/lib/fixture_template.rb
parent39e4e76d15233bb1cb0b778d920f54efe86bb4f0 (diff)
parent1a0f822037c408a392ffa7b6e1ecbe5951ab48db (diff)
downloadrails-670281c6b2e9b9e8c51a140f2a5f66b251f1b84b.tar.gz
rails-670281c6b2e9b9e8c51a140f2a5f66b251f1b84b.tar.bz2
rails-670281c6b2e9b9e8c51a140f2a5f66b251f1b84b.zip
Merge commit 'rails/master'
Conflicts: activerecord/lib/active_record/associations.rb
Diffstat (limited to 'actionpack/test/lib/fixture_template.rb')
-rw-r--r--actionpack/test/lib/fixture_template.rb61
1 files changed, 9 insertions, 52 deletions
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb
index 8da92180d1..6b9e7c5270 100644
--- a/actionpack/test/lib/fixture_template.rb
+++ b/actionpack/test/lib/fixture_template.rb
@@ -1,67 +1,24 @@
module ActionView #:nodoc:
- class FixtureResolver < Resolver
+ class FixtureResolver < PathResolver
def initialize(hash = {}, options = {})
super(options)
@hash = hash
end
- def find_templates(name, details, prefix, partial)
- if regexp = details_to_regexp(name, details, prefix, partial)
- cached(regexp) do
- templates = []
- @hash.select { |k,v| k =~ regexp }.each do |path, source|
- templates << Template.new(source, path, *path_to_details(path))
- end
- templates.sort_by {|t| -t.details.values.compact.size }
- end
- end
- end
-
private
- def formats_regexp
- @formats_regexp ||= begin
- formats = Mime::SET.symbols
- '(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?'
+ def query(path, exts)
+ query = Regexp.escape(path)
+ exts.each do |ext|
+ query << '(?:' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << ')'
end
- end
-
- def handler_regexp
- e = TemplateHandlers.extensions.map{|h| "\\.#{Regexp.escape(h.to_s)}"}.join("|")
- "(?:#{e})"
- end
- def details_to_regexp(name, details, prefix, partial)
- path = ""
- path << "#{prefix}/" unless prefix.empty?
- path << (partial ? "_#{name}" : name)
-
- extensions = ""
- [:locales, :formats].each do |k|
- extensions << if exts = details[k]
- '(?:' + exts.map {|e| "\\.#{Regexp.escape(e.to_s)}"}.join('|') + ')?'
- else
- k == :formats ? formats_regexp : ''
- end
+ templates = []
+ @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
+ templates << Template.new(source, path, *path_to_details(path))
end
-
- %r'^#{Regexp.escape(path)}#{extensions}#{handler_regexp}$'
+ templates.sort_by {|t| -t.details.values.compact.size }
end
- # TODO: fix me
- # :api: plugin
- def path_to_details(path)
- # [:erb, :format => :html, :locale => :en, :partial => true/false]
- if m = path.match(%r'(_)?[\w-]+((?:\.[\w-]+)*)\.(\w+)$')
- partial = m[1] == '_'
- details = (m[2]||"").split('.').reject { |e| e.empty? }
- handler = Template.handler_class_for_extension(m[3])
-
- format = Mime[details.last] && details.pop.to_sym
- locale = details.last && details.pop.to_sym
-
- return handler, :format => format, :locale => locale, :partial => partial
- end
- end
end
end \ No newline at end of file