aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/lib/fixture_template.rb
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-04-27 18:21:26 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-01 17:31:01 -0700
commit8a4e77b4200946ba4ed42fe5927a7400a846063a (patch)
tree4d61ebd026f32bd9af32c93f93b3071232b1d8ee /actionpack/test/lib/fixture_template.rb
parent34509777fd375e5bc529f21ca66cf63263c2cf64 (diff)
downloadrails-8a4e77b4200946ba4ed42fe5927a7400a846063a.tar.gz
rails-8a4e77b4200946ba4ed42fe5927a7400a846063a.tar.bz2
rails-8a4e77b4200946ba4ed42fe5927a7400a846063a.zip
OMG, a lot of work
Diffstat (limited to 'actionpack/test/lib/fixture_template.rb')
-rw-r--r--actionpack/test/lib/fixture_template.rb115
1 files changed, 92 insertions, 23 deletions
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb
index 26f6ec2d0c..e43e329a9e 100644
--- a/actionpack/test/lib/fixture_template.rb
+++ b/actionpack/test/lib/fixture_template.rb
@@ -1,35 +1,104 @@
module ActionView #:nodoc:
- class FixtureTemplate < Template
- class FixturePath < Template::Path
- def initialize(hash = {})
- @hash = {}
-
- hash.each do |k, v|
- @hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self)
+class Template
+ class FixturePath < Path
+ 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
end
-
- super("fixtures://root")
- end
-
- def find_template(path)
- @hash[path]
end
end
- def initialize(body, *args)
- @body = body
- super(*args)
+ private
+
+ def formats_regexp
+ @formats_regexp ||= begin
+ formats = Mime::SET.map { |m| m.symbol }
+ '(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?'
+ end
end
- def source
- @body
+ def handler_regexp
+ e = TemplateHandlers.extensions.map{|h| "\\.#{Regexp.escape(h.to_s)}"}.join("|")
+ "(?:#{e})?"
end
- private
-
- def find_full_path(path, load_paths)
- return '/', path
+ 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
+ end
+
+ %r'#{Regexp.escape(path)}#{extensions}#{handler_regexp}'
+ 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
+
+
+ # class FixtureTemplate < Template
+ # class FixturePath < Template::Path
+ # def initialize(hash = {})
+ # @hash = {}
+ #
+ # hash.each do |k, v|
+ # @hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self)
+ # end
+ #
+ # super("fixtures://root")
+ # end
+ #
+ # def find_template(path)
+ # @hash[path]
+ # end
+ # end
+ #
+ # def initialize(body, *args)
+ # @body = body
+ # super(*args)
+ # end
+ #
+ # def source
+ # @body
+ # end
+ #
+ # private
+ #
+ # def find_full_path(path, load_paths)
+ # return '/', path
+ # end
+ #
+ # end
+end
end \ No newline at end of file