mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Get rid of ruby warnings in Resolvers. Move a few methods up to the abstract class.
This commit is contained in:
parent
ea30da3069
commit
243513f4d1
2 changed files with 26 additions and 23 deletions
|
@ -6,7 +6,6 @@ module ActionView
|
||||||
# = Action View Resolver
|
# = Action View Resolver
|
||||||
class Resolver
|
class Resolver
|
||||||
def initialize
|
def initialize
|
||||||
@path = nil
|
|
||||||
@cached = Hash.new { |h1,k1| h1[k1] =
|
@cached = Hash.new { |h1,k1| h1[k1] =
|
||||||
Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } }
|
Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } }
|
||||||
end
|
end
|
||||||
|
@ -35,6 +34,23 @@ module ActionView
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
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)
|
def cached(key, prefix, name, partial)
|
||||||
return yield unless key && caching?
|
return yield unless key && caching?
|
||||||
@cached[key][prefix][name][partial] ||= yield
|
@cached[key][prefix][name][partial] ||= yield
|
||||||
|
@ -44,25 +60,13 @@ module ActionView
|
||||||
class PathResolver < Resolver
|
class PathResolver < Resolver
|
||||||
EXTENSION_ORDER = [:locale, :formats, :handlers]
|
EXTENSION_ORDER = [:locale, :formats, :handlers]
|
||||||
|
|
||||||
def to_s
|
private
|
||||||
@path.to_s
|
|
||||||
end
|
|
||||||
alias :to_path :to_s
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def find_templates(name, prefix, partial, details)
|
def find_templates(name, prefix, partial, details)
|
||||||
path = build_path(name, prefix, partial, details)
|
path = build_path(name, prefix, partial, details)
|
||||||
query(path, EXTENSION_ORDER.map { |ext| details[ext] }, details[:formats])
|
query(path, EXTENSION_ORDER.map { |ext| details[ext] }, details[:formats])
|
||||||
end
|
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)
|
def query(path, exts, formats)
|
||||||
query = File.join(@path, path)
|
query = File.join(@path, path)
|
||||||
|
|
||||||
|
@ -86,13 +90,7 @@ module ActionView
|
||||||
def extract_handler_and_format(path, default_formats)
|
def extract_handler_and_format(path, default_formats)
|
||||||
pieces = File.basename(path).split(".")
|
pieces = File.basename(path).split(".")
|
||||||
pieces.shift
|
pieces.shift
|
||||||
|
retrieve_handler_and_format(pieces.pop, pieces.pop, default_formats)
|
||||||
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]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -103,6 +101,11 @@ module ActionView
|
||||||
@path = File.expand_path(path)
|
@path = File.expand_path(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
@path.to_s
|
||||||
|
end
|
||||||
|
alias :to_path :to_s
|
||||||
|
|
||||||
def eql?(resolver)
|
def eql?(resolver)
|
||||||
self.class.equal?(resolver.class) && to_path == resolver.to_path
|
self.class.equal?(resolver.class) && to_path == resolver.to_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ module ActionView #:nodoc:
|
||||||
@hash = hash
|
@hash = hash
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def query(path, exts, formats)
|
def query(path, exts, formats)
|
||||||
query = Regexp.escape(path)
|
query = Regexp.escape(path)
|
||||||
|
@ -32,7 +32,7 @@ module ActionView #:nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NullResolver < ActionView::PathResolver
|
class NullResolver < PathResolver
|
||||||
def query(path, exts, formats)
|
def query(path, exts, formats)
|
||||||
handler, format = extract_handler_and_format(path, formats)
|
handler, format = extract_handler_and_format(path, formats)
|
||||||
[ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)]
|
[ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)]
|
||||||
|
|
Loading…
Reference in a new issue