提交 010a0c92 编写于 作者: Y Yehuda Katz

Rename find_by_parts and find_by_parts? to find and exists?

上级 55575e21
......@@ -499,7 +499,7 @@ def create!(method_name, *parameters) #:nodoc:
# ====
# TODO: Revisit this
# template_exists = @parts.empty?
# template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}")
# template_exists ||= template_root.find("#{mailer_name}/#{@template}")
# @body = render_message(@template, @body) if template_exists
# Finally, if there are other message parts and a textual body exists,
......@@ -585,7 +585,7 @@ def render(opts)
if file
prefix = mailer_name unless file =~ /\//
template = view_paths.find_by_parts(file, {:formats => formats}, prefix)
template = view_paths.find(file, {:formats => formats}, prefix)
end
layout = _pick_layout(layout,
......
......@@ -76,7 +76,7 @@ def _layout(details)
when nil
self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
def _layout(details)
if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts")
if view_paths.exists?("#{_implied_layout_name}", details, "layouts")
"#{_implied_layout_name}"
else
super
......@@ -131,7 +131,7 @@ def _layout_for_name(name, details = {:formats => formats})
def _find_layout(name, details)
# TODO: Make prefix actually part of details in ViewPath#find_by_parts
prefix = details.key?(:prefix) ? details.delete(:prefix) : "layouts"
view_paths.find_by_parts(name, details, prefix)
view_paths.find(name, details, prefix)
end
# Returns the default layout for this controller and a given set of details.
......
......@@ -111,7 +111,7 @@ def self.body_to_s(body)
def _determine_template(options)
name = (options[:_template_name] || action_name).to_s
options[:_template] ||= view_paths.find_by_parts(
options[:_template] ||= view_paths.find(
name, { :formats => formats }, options[:_prefix], options[:_partial]
)
end
......
......@@ -51,7 +51,7 @@ def default_render
def method_for_action(action_name)
super || begin
if view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
if view_paths.exists?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
"default_render"
end
end
......
......@@ -191,7 +191,7 @@ def default_layout(*args)
def memoized_find_layout(layout, formats) #:nodoc:
return layout if layout.nil? || layout.respond_to?(:render)
prefix = layout.to_s =~ /layouts\// ? nil : "layouts"
view_paths.find_by_parts(layout.to_s, {:formats => formats}, prefix)
view_paths.find(layout.to_s, {:formats => formats}, prefix)
end
def find_layout(*args)
......
......@@ -202,7 +202,7 @@ def self.cache_template_loading?
delegate :logger, :to => :controller, :allow_nil => true
delegate :find_by_parts, :to => :view_paths
delegate :find, :to => :view_paths
include Context
......
......@@ -33,12 +33,12 @@ def unshift(*objs)
super(*objs.map { |obj| self.class.type_cast(obj) })
end
def find_by_parts(path, details = {}, prefix = nil, partial = false)
def find(path, details = {}, prefix = nil, partial = false)
# template_path = path.sub(/^\//, '')
template_path = path
each do |load_path|
if template = load_path.find_by_parts(template_path, details, prefix, partial)
if template = load_path.find(template_path, details, prefix, partial)
return template
end
end
......@@ -48,11 +48,11 @@ def find_by_parts(path, details = {}, prefix = nil, partial = false)
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path} - #{details.inspect} - partial: #{!!partial}")
end
def find_by_parts?(path, extension = nil, prefix = nil, partial = false)
def exists?(path, extension = nil, prefix = nil, partial = false)
template_path = path.sub(/^\//, '')
each do |load_path|
return true if template = load_path.find_by_parts(template_path, extension, prefix, partial)
return true if template = load_path.find(template_path, extension, prefix, partial)
end
false
end
......@@ -62,7 +62,7 @@ def find_template(original_template_path, format = nil, html_fallback = true)
template_path = original_template_path.sub(/^\//, '')
each do |load_path|
if template = load_path.find_by_parts(template_path, format)
if template = load_path.find(template_path, format)
return template
# Try to find html version if the format is javascript
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
......
......@@ -258,7 +258,7 @@ def _render_partial_collection(collection, options = {}, template = nil, &block)
def _pick_partial_template(partial_path) #:nodoc:
prefix = controller_path unless partial_path.include?(?/)
find_by_parts(partial_path, {:formats => formats}, prefix, true)
find(partial_path, {:formats => formats}, prefix, true)
end
end
end
......@@ -24,10 +24,10 @@ def render(options = {}, locals = {}, &block) #:nodoc:
return _render_content(_render_partial(options), layout, options[:locals])
end
layout = find_by_parts(layout, {:formats => formats}) if layout
layout = find(layout, {:formats => formats}) if layout
if file = options[:file]
template = find_by_parts(file, {:formats => formats})
template = find(file, {:formats => formats})
_render_template(template, layout, :locals => options[:locals] || {})
elsif inline = options[:inline]
_render_inline(inline, layout, options)
......
......@@ -10,7 +10,7 @@ def initialize(options)
end
# Normalizes the arguments and passes it on to find_template
def find_by_parts(*args)
def find(*args)
find_all_by_parts(*args).first
end
......
......@@ -139,10 +139,10 @@ class WithLayouts < PrefixedViews
private
def self.layout(formats)
begin
view_paths.find_by_parts(name.underscore, {:formats => formats}, "layouts")
view_paths.find(name.underscore, {:formats => formats}, "layouts")
rescue ActionView::MissingTemplate
begin
view_paths.find_by_parts("application", {:formats => formats}, "layouts")
view_paths.find("application", {:formats => formats}, "layouts")
rescue ActionView::MissingTemplate
end
end
......
......@@ -4,7 +4,7 @@ module AbstractController
module Testing
class ControllerWithHelpers < AbstractController::Base
include RenderingController
include AbstractController::RenderingController
include Helpers
def render(string)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册