aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/lookup_context.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-16 02:08:34 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-16 02:09:16 +0100
commit8dd731bc502a07f4fb76eb2706a1f3bca479ef63 (patch)
tree469e95a8f2f17b06250189d34211cef435a885c7 /actionpack/lib/action_view/lookup_context.rb
parent1f5e2f2bad3c33ec52312a1700bacf06a71875a5 (diff)
downloadrails-8dd731bc502a07f4fb76eb2706a1f3bca479ef63.tar.gz
rails-8dd731bc502a07f4fb76eb2706a1f3bca479ef63.tar.bz2
rails-8dd731bc502a07f4fb76eb2706a1f3bca479ef63.zip
Move more normalization up to the lookup context, so it does not have to repeat in every resolver.
Diffstat (limited to 'actionpack/lib/action_view/lookup_context.rb')
-rw-r--r--actionpack/lib/action_view/lookup_context.rb36
1 files changed, 30 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 8eb17bf8f1..598007c7a4 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -15,12 +15,10 @@ module ActionView
def self.register_detail(name, options = {}, &block)
self.registered_details << name
-
Setters.send :define_method, :"_#{name}_defaults", &block
Setters.module_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{name}=(value)
value = Array(value.presence || _#{name}_defaults)
- #{"value << nil unless value.include?(nil)" unless options[:allow_nil] == false}
unless value == @details[:#{name}]
@details_key, @details = nil, @details.merge(:#{name} => value)
@@ -69,16 +67,16 @@ module ActionView
end
def find(name, prefix = nil, partial = false)
- @view_paths.find(name, prefix, partial, details, details_key)
+ @view_paths.find(*args_for_lookup(name, prefix, partial))
end
alias :find_template :find
def find_all(name, prefix = nil, partial = false)
- @view_paths.find_all(name, prefix, partial, details, details_key)
+ @view_paths.find_all(*args_for_lookup(name, prefix, partial))
end
def exists?(name, prefix = nil, partial = false)
- @view_paths.exists?(name, prefix, partial, details, details_key)
+ @view_paths.exists?(*args_for_lookup(name, prefix, partial))
end
alias :template_exists? :exists?
@@ -94,6 +92,32 @@ module ActionView
ensure
added_resolvers.times { view_paths.pop }
end
+
+ protected
+
+ def args_for_lookup(name, prefix, partial) #:nodoc:
+ name, prefix = normalize_name(name, prefix)
+ details_key = self.details_key
+ details = self.details.merge(:handlers => default_handlers)
+ [name, prefix, partial || false, details, details_key]
+ end
+
+ # Support legacy foo.erb names even though we now ignore .erb
+ # as well as incorrectly putting part of the path in the template
+ # name instead of the prefix.
+ def normalize_name(name, prefix) #:nodoc:
+ name = name.to_s.gsub(handlers_regexp, '')
+ parts = name.split('/')
+ return parts.pop, [prefix, *parts].compact.join("/")
+ end
+
+ def default_handlers #:nodoc:
+ @detault_handlers ||= Template::Handlers.extensions
+ end
+
+ def handlers_regexp #:nodoc:
+ @handlers_regexp ||= /\.(?:#{default_handlers.join('|')})$/
+ end
end
module Details
@@ -113,7 +137,7 @@ module ActionView
end
# Overload formats= to reject [:"*/*"] values.
- def formats=(value, freeze=true)
+ def formats=(value)
value = nil if value == [:"*/*"]
super(value)
end