aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-08 23:13:24 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-08 23:25:16 +0100
commit8f082ff4217175f52234f2223658619a9c923afc (patch)
tree10b106df434109c5b5a117a06239a86be8266053 /actionpack/lib/action_view
parent01f0e47663bbbc593af0c36d4cf49124b200e3d8 (diff)
downloadrails-8f082ff4217175f52234f2223658619a9c923afc.tar.gz
rails-8f082ff4217175f52234f2223658619a9c923afc.tar.bz2
rails-8f082ff4217175f52234f2223658619a9c923afc.zip
Clean LookupContext API.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/lookup_context.rb10
-rw-r--r--actionpack/lib/action_view/paths.rb29
-rw-r--r--actionpack/lib/action_view/render/layouts.rb4
-rw-r--r--actionpack/lib/action_view/render/partials.rb2
-rw-r--r--actionpack/lib/action_view/render/rendering.rb8
-rw-r--r--actionpack/lib/action_view/template/resolver.rb16
7 files changed, 32 insertions, 39 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 38413560f3..564ea6684c 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -194,7 +194,7 @@ module ActionView #:nodoc:
attr_accessor :base_path, :assigns, :template_extension, :lookup_context
attr_internal :captures, :request, :layout, :controller, :template, :config
- delegate :find_template, :template_exists?, :formats, :formats=,
+ delegate :find, :exists?, :formats, :formats=,
:view_paths, :view_paths=, :with_fallbacks, :update_details, :to => :lookup_context
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 608f1ef818..4a4dc0d06c 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -59,19 +59,19 @@ module ActionView
@view_paths = ActionView::Base.process_view_paths(paths)
end
- def find_template(name, prefix = nil, partial = false)
+ def find(name, prefix = nil, partial = false)
key = details_key
- @view_paths.find(name, key.details, prefix, partial || false, key)
+ @view_paths.find(name, prefix, partial || false, key.details, key)
end
def find_all(name, prefix = nil, partial = false)
key = details_key
- @view_paths.find_all(name, key.details, prefix, partial || false, key)
+ @view_paths.find_all(name, prefix, partial || false, key.details, key)
end
- def template_exists?(name, prefix = nil, partial = false)
+ def exists?(name, prefix = nil, partial = false)
key = details_key
- @view_paths.exists?(name, key.details, prefix, partial || false, key)
+ @view_paths.exists?(name, prefix, partial || false, key.details, key)
end
# Add fallbacks to the view paths. Useful in cases you are rendering a file.
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb
index 82a9f9a13c..35927d09d1 100644
--- a/actionpack/lib/action_view/paths.rb
+++ b/actionpack/lib/action_view/paths.rb
@@ -9,31 +9,22 @@ module ActionView #:nodoc:
METHOD
end
- def find_all(path, details = {}, prefix = nil, partial = false, key=nil)
+ def find(path, prefix = nil, partial = false, details = {}, key = nil)
+ template = find_all(path, prefix, partial, details, key).first
+ raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template
+ template
+ end
+
+ def find_all(*args)
each do |resolver|
- templates = resolver.find_all(path, details, prefix, partial, key)
+ templates = resolver.find_all(*args)
return templates unless templates.empty?
end
[]
end
- def find(path, details = {}, prefix = nil, partial = false, key=nil)
- each do |resolver|
- if template = resolver.find(path, details, prefix, partial, key)
- return template
- end
- end
-
- raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}", details, partial)
- end
-
- def exists?(path, details = {}, prefix = nil, partial = false, key=nil)
- each do |resolver|
- if resolver.find(path, details, prefix, partial, key)
- return true
- end
- end
- false
+ def exists?(*args)
+ find_all(*args).any?
end
protected
diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb
index 91a92a833a..8688de3d18 100644
--- a/actionpack/lib/action_view/render/layouts.rb
+++ b/actionpack/lib/action_view/render/layouts.rb
@@ -49,10 +49,10 @@ module ActionView
def _find_layout(layout) #:nodoc:
begin
layout =~ /^\// ?
- with_fallbacks { find_template(layout) } : find_template(layout)
+ with_fallbacks { find(layout) } : find(layout)
rescue ActionView::MissingTemplate => e
update_details(:formats => nil) do
- raise unless template_exists?(layout)
+ raise unless exists?(layout)
end
end
end
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index 0fe2d560f7..950c9d2cd8 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -294,7 +294,7 @@ module ActionView
def find_template(path=@path)
return path unless path.is_a?(String)
prefix = @view.controller_path unless path.include?(?/)
- @view.find_template(path, prefix, true)
+ @view.find(path, prefix, true)
end
def partial_path(object = @object)
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 0322d4b641..47ea70f5ad 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -29,8 +29,6 @@ module ActionView
end
# This is the API to render a ViewContext's template from a controller.
- # TODO Review this name since it does not render only templates, but also
- # partials, files and so forth.
def render_template(options, &block)
_evaluate_assigns_and_ivars
@@ -62,12 +60,12 @@ module ActionView
Template.new(options[:inline], "inline template", handler, {})
elsif options.key?(:text)
Template::Text.new(options[:text], self.formats.try(:first))
- elsif options.key?(:file)
- with_fallbacks { find_template(options[:file], options[:_prefix]) }
elsif options.key?(:_template)
options[:_template]
+ elsif options.key?(:file)
+ with_fallbacks { find(options[:file], options[:prefix]) }
elsif options.key?(:template)
- find_template(options[:template], options[:_prefix])
+ find(options[:template], options[:prefix])
end
end
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index 9a011f7638..6e6c4c21ee 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -10,16 +10,20 @@ module ActionView
Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } }
end
+ def clear_cache
+ @cached.clear
+ end
+
def find(*args)
find_all(*args).first
end
# Normalizes the arguments and passes it on to find_template.
- def find_all(name, details = {}, prefix = nil, partial = nil, key=nil)
+ def find_all(name, prefix=nil, partial=false, details={}, key=nil)
name, prefix = normalize_name(name, prefix)
cached(key, prefix, name, partial) do
- find_templates(name, details, prefix, partial)
+ find_templates(name, prefix, partial, details)
end
end
@@ -32,7 +36,7 @@ module ActionView
# This is what child classes implement. No defaults are needed
# because Resolver guarantees that the arguments are present and
# normalized.
- def find_templates(name, details, prefix, partial)
+ def find_templates(name, prefix, partial, details)
raise NotImplementedError
end
@@ -68,12 +72,12 @@ module ActionView
private
- def find_templates(name, details, prefix, partial)
- path = build_path(name, details, prefix, partial)
+ def find_templates(name, prefix, partial, details)
+ path = build_path(name, prefix, partial, details)
query(path, EXTENSION_ORDER.map { |ext| details[ext] })
end
- def build_path(name, details, prefix, partial)
+ def build_path(name, prefix, partial, details)
path = ""
path << "#{prefix}/" unless prefix.empty?
path << (partial ? "_#{name}" : name)