aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template/resolver.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-10-07 13:26:58 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-07 16:46:12 +0200
commit243513f4d17e62186ef0499edece1588c79220b2 (patch)
treee385bc3430335652a985ed55164ffe87a1a0bb3e /actionpack/lib/action_view/template/resolver.rb
parentea30da30699f588bee4dc4713859fe035d6243db (diff)
downloadrails-243513f4d17e62186ef0499edece1588c79220b2.tar.gz
rails-243513f4d17e62186ef0499edece1588c79220b2.tar.bz2
rails-243513f4d17e62186ef0499edece1588c79220b2.zip
Get rid of ruby warnings in Resolvers. Move a few methods up to the abstract class.
Diffstat (limited to 'actionpack/lib/action_view/template/resolver.rb')
-rw-r--r--actionpack/lib/action_view/template/resolver.rb45
1 files changed, 24 insertions, 21 deletions
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index a261e08dbc..a031d0dc33 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -6,7 +6,6 @@ module ActionView
# = Action View Resolver
class Resolver
def initialize
- @path = nil
@cached = Hash.new { |h1,k1| h1[k1] =
Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } }
end
@@ -35,6 +34,23 @@ module ActionView
raise NotImplementedError
end
+ # Helpers that builds a path. Useful for building virtual paths.
+ def build_path(name, prefix, partial, details)
+ path = ""
+ path << "#{prefix}/" unless prefix.empty?
+ path << (partial ? "_#{name}" : name)
+ path
+ end
+
+ # Get the handler and format from the given parameters.
+ def retrieve_handler_and_format(handler, format, default_formats=nil)
+ handler = Template.handler_class_for_extension(handler)
+ format = format && Mime[format]
+ format ||= handler.default_format if handler.respond_to?(:default_format)
+ format ||= default_formats
+ [handler, format]
+ end
+
def cached(key, prefix, name, partial)
return yield unless key && caching?
@cached[key][prefix][name][partial] ||= yield
@@ -44,25 +60,13 @@ module ActionView
class PathResolver < Resolver
EXTENSION_ORDER = [:locale, :formats, :handlers]
- def to_s
- @path.to_s
- end
- alias :to_path :to_s
-
- private
+ private
def find_templates(name, prefix, partial, details)
path = build_path(name, prefix, partial, details)
query(path, EXTENSION_ORDER.map { |ext| details[ext] }, details[:formats])
end
- def build_path(name, prefix, partial, details)
- path = ""
- path << "#{prefix}/" unless prefix.empty?
- path << (partial ? "_#{name}" : name)
- path
- end
-
def query(path, exts, formats)
query = File.join(@path, path)
@@ -86,13 +90,7 @@ module ActionView
def extract_handler_and_format(path, default_formats)
pieces = File.basename(path).split(".")
pieces.shift
-
- handler = Template.handler_class_for_extension(pieces.pop)
- format = pieces.last && Mime[pieces.last] && pieces.pop.to_sym
- format ||= handler.default_format if handler.respond_to?(:default_format)
- format ||= default_formats
-
- [handler, format]
+ retrieve_handler_and_format(pieces.pop, pieces.pop, default_formats)
end
end
@@ -103,6 +101,11 @@ module ActionView
@path = File.expand_path(path)
end
+ def to_s
+ @path.to_s
+ end
+ alias :to_path :to_s
+
def eql?(resolver)
self.class.equal?(resolver.class) && to_path == resolver.to_path
end