aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-09-22 15:03:05 +0200
committerJosé Valim <jose.valim@gmail.com>2011-09-22 15:03:05 +0200
commit119e9e2dafb0cdc5b85613b730333679aef534af (patch)
treed2d26382e4f606a5c13d7c76cd48ed3f57f11b36 /actionpack/lib
parentcbaad674f13067c52fa8c1a24dc498e570db4eed (diff)
downloadrails-119e9e2dafb0cdc5b85613b730333679aef534af.tar.gz
rails-119e9e2dafb0cdc5b85613b730333679aef534af.tar.bz2
rails-119e9e2dafb0cdc5b85613b730333679aef534af.zip
Get rid of update_details in favor of passing details to find_template.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/lookup_context.rb33
-rw-r--r--actionpack/lib/action_view/renderer/abstract_renderer.rb16
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb23
-rw-r--r--actionpack/lib/action_view/renderer/template_renderer.rb27
4 files changed, 33 insertions, 66 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 96ef7da01b..8267977830 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -20,18 +20,16 @@ module ActionView
def self.register_detail(name, options = {}, &block)
self.registered_details << name
-
initialize = registered_details.map { |n| "self.#{n} = details[:#{n}]" }
- update = registered_details.map { |n| "self.#{n} = details[:#{n}] if details.key?(:#{n})" }
- Accessors.send :define_method, :"_#{name}_defaults", &block
+ Accessors.send :define_method, :"default_#{name}", &block
Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{name}
@details[:#{name}]
end
def #{name}=(value)
- value = Array.wrap(value.presence || _#{name}_defaults)
+ value = Array.wrap(value.presence || default_#{name})
_set_detail(:#{name}, value) if value != @details[:#{name}]
end
@@ -39,11 +37,6 @@ module ActionView
def initialize_details(details)
#{initialize.join("\n")}
end
-
- remove_possible_method :update_details
- def update_details(details)
- #{update.join("\n")}
- end
METHOD
end
@@ -88,24 +81,6 @@ module ActionView
@cache = old_value
end
- # Update the details keys by merging the given hash into the current
- # details hash. If a block is given, the details are modified just during
- # the execution of the block and reverted to the previous value after.
- def update_details(new_details)
- if block_given?
- old_details, old_key = @details.dup, @details_key
- super
-
- begin
- yield
- ensure
- @details, @details_key = old_details, old_key
- end
- else
- super
- end
- end
-
protected
def _set_detail(key, value)
@@ -220,7 +195,7 @@ module ActionView
# add :html as fallback to :js.
def formats=(values)
if values
- values.concat(_formats_defaults) if values.delete "*/*"
+ values.concat(default_formats) if values.delete "*/*"
values << :html if values == [:js]
end
super(values)
@@ -246,7 +221,7 @@ module ActionView
config.locale = value
end
- super(@skip_default_locale ? I18n.locale : _locale_defaults)
+ super(@skip_default_locale ? I18n.locale : default_locale)
end
# A method which only uses the first format in the formats array for layout lookup.
diff --git a/actionpack/lib/action_view/renderer/abstract_renderer.rb b/actionpack/lib/action_view/renderer/abstract_renderer.rb
index 60c527beeb..24bae64ca5 100644
--- a/actionpack/lib/action_view/renderer/abstract_renderer.rb
+++ b/actionpack/lib/action_view/renderer/abstract_renderer.rb
@@ -11,15 +11,13 @@ module ActionView
raise NotImplementedError
end
- # Checks if the given path contains a format and if so, change
- # the lookup context to take this new format into account.
- def wrap_formats(value)
- return yield unless value.is_a?(String)
+ protected
- if value.sub!(formats_regexp, "")
- update_details(:formats => [$1.to_sym]){ yield }
- else
- yield
+ def extract_format(value, details)
+ if value.is_a?(String) && value.sub!(formats_regexp, "")
+ ActiveSupport::Deprecation.warn "Passing the format in the template name is deprecated. " \
+ "Please pass render with :formats => #{$1} instead.", caller
+ details[:formats] ||= [$1.to_sym]
end
end
@@ -27,8 +25,6 @@ module ActionView
@@formats_regexp ||= /\.(#{Mime::SET.symbols.join('|')})$/
end
- protected
-
def instrument(name, options={})
ActiveSupport::Notifications.instrument("render_#{name}.action_view", options){ yield }
end
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index cd0f7054a9..fc39ee8498 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -216,18 +216,15 @@ module ActionView
def render(context, options, block)
setup(context, options, block)
+ identifier = (@template = find_partial) ? @template.identifier : @path
- wrap_formats(@path) do
- identifier = ((@template = find_partial) ? @template.identifier : @path)
-
- if @collection
- instrument(:collection, :identifier => identifier || "collection", :count => @collection.size) do
- render_collection
- end
- else
- instrument(:partial, :identifier => identifier) do
- render_partial
- end
+ if @collection
+ instrument(:collection, :identifier => identifier || "collection", :count => @collection.size) do
+ render_collection
+ end
+ else
+ instrument(:partial, :identifier => identifier) do
+ render_partial
end
end
end
@@ -271,6 +268,7 @@ module ActionView
@options = options
@locals = options[:locals] || {}
@block = block
+ @details = options.slice(:formats, :locale, :handlers)
if String === partial
@object = options[:object]
@@ -299,6 +297,7 @@ module ActionView
"and is followed by any combinations of letters, numbers, or underscores.")
end
+ extract_format(@path, @details)
self
end
@@ -326,7 +325,7 @@ module ActionView
def find_template(path=@path, locals=@locals.keys)
prefixes = path.include?(?/) ? [] : @lookup_context.prefixes
- @lookup_context.find_template(path, prefixes, true, locals)
+ @lookup_context.find_template(path, prefixes, true, locals, @details)
end
def collection_with_template
diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb
index 0a5b470a82..f3e7378f2b 100644
--- a/actionpack/lib/action_view/renderer/template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/template_renderer.rb
@@ -4,30 +4,28 @@ require 'active_support/core_ext/array/wrap'
module ActionView
class TemplateRenderer < AbstractRenderer #:nodoc:
def render(context, options)
- @view = context
-
- wrap_formats(options[:template] || options[:file]) do
- template = determine_template(options)
- freeze_formats(template.formats, true)
- render_template(template, options[:layout], options[:locals])
- end
+ @view = context
+ @details = options.slice(:formats, :locale, :handlers)
+ extract_format(options[:file] || options[:template], @details)
+ template = determine_template(options)
+ freeze_formats(template.formats, true)
+ render_template(template, options[:layout], options[:locals])
end
# Determine the template to be rendered using the given options.
def determine_template(options) #:nodoc:
- keys = options[:locals].try(:keys) || []
- details = options.slice(:formats, :locale, :handlers)
+ keys = options[:locals].try(:keys) || []
if options.key?(:text)
Template::Text.new(options[:text], formats.try(:first))
elsif options.key?(:file)
- with_fallbacks { find_template(options[:file], nil, false, keys, details) }
+ with_fallbacks { find_template(options[:file], nil, false, keys, @details) }
elsif options.key?(:inline)
handler = Template.handler_for_extension(options[:type] || "erb")
Template.new(options[:inline], "inline template", handler, :locals => keys)
elsif options.key?(:template)
options[:template].respond_to?(:render) ?
- options[:template] : find_template(options[:template], options[:prefixes], false, keys)
+ options[:template] : find_template(options[:template], options[:prefixes], false, keys, @details)
end
end
@@ -63,12 +61,11 @@ module ActionView
begin
with_layout_format do
layout =~ /^\// ?
- with_fallbacks { find_template(layout, nil, false, keys) } : find_template(layout, nil, false, keys)
+ with_fallbacks { find_template(layout, nil, false, keys, @details) } : find_template(layout, nil, false, keys, @details)
end
rescue ActionView::MissingTemplate
- update_details(:formats => nil) do
- raise unless template_exists?(layout)
- end
+ all_details = @details.merge(:formats => @lookup_context.default_formats)
+ raise unless template_exists?(layout, nil, false, keys, all_details)
end
end
end