Final tidy up on templates inheritance.

This commit is contained in:
José Valim 2010-12-27 09:14:13 +01:00
parent e03e1fdbc8
commit 51a7d9acdd
5 changed files with 15 additions and 17 deletions

@ -1,8 +1,10 @@
*Rails 3.1.0 (unreleased)*
* brought back config.action_view.cache_template_loading, which allows to decide whether templates should be cached or not [Piotr Sarnacki]
* Template lookup now searches further up in the inheritance chain. [Artemave]
* url_for and named url helpers now accept :subdomain and :domain as options [Josh Kalderimis]
* Brought back config.action_view.cache_template_loading, which allows to decide whether templates should be cached or not. [Piotr Sarnacki]
* url_for and named url helpers now accept :subdomain and :domain as options, [Josh Kalderimis]
* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused (check the documentation for examples). [Josh Kalderimis]

@ -119,13 +119,14 @@ def normalize_name(name, prefixes) #:nodoc:
name = name.to_s.gsub(handlers_regexp, '')
parts = name.split('/')
name = parts.pop
prx = if prefixes.blank?
[parts.compact.join('/')]
else
prefixes.map {|prefix| [prefix, *parts].compact.join('/') }
end
return name, prx
prefixes = if prefixes.blank?
[parts.join('/')]
else
prefixes.map { |prefix| [prefix, *parts].compact.join('/') }
end
return name, prefixes
end
def default_handlers #:nodoc:

@ -21,26 +21,21 @@ def find(*args)
def find_all(path, prefixes = [], *args)
prefixes.each do |prefix|
templates = []
each do |resolver|
templates.concat resolver.find_all(path, prefix, *args)
end
return templates unless templates.empty?
end
[]
end
def find_first(path, prefixes = [], *args)
prefixes.each do |prefix|
each do |resolver|
if template = resolver.find_all(path, prefix, *args).first
return template
end
template = resolver.find_all(path, prefix, *args).first
return template if template
end
end
nil
end

@ -111,7 +111,7 @@ def find_partial
end
def find_template(path=@path, locals=@locals.keys)
prefixes = path.include?(?/) ? [] : @view.controller._prefixes
prefixes = path.include?(?/) ? [] : @view.controller_prefixes
@lookup_context.find_template(path, prefixes, true, locals)
end

@ -43,7 +43,7 @@ def determine_template(options) #:nodoc:
if options.key?(:text)
Template::Text.new(options[:text], formats.try(:first))
elsif options.key?(:file)
with_fallbacks { find_template(options[:file], [], false, keys) }
with_fallbacks { find_template(options[:file], options[:prefixes], false, keys) }
elsif options.key?(:inline)
handler = Template.handler_for_extension(options[:type] || "erb")
Template.new(options[:inline], "inline template", handler, :locals => keys)