aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-23 22:53:26 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-23 22:53:26 +0100
commitf915f9e33903ee474920e24ad12a1625f2ef1c52 (patch)
tree5b6d41e8a809aeaadbc2c0be59603f5f58b16231 /actionpack
parentb17e358e3df34c03019e357f693611618092e1d6 (diff)
parent8ff2fb6f3aa6140f5a8bd018d5919a8a1e707cda (diff)
downloadrails-f915f9e33903ee474920e24ad12a1625f2ef1c52.tar.gz
rails-f915f9e33903ee474920e24ad12a1625f2ef1c52.tar.bz2
rails-f915f9e33903ee474920e24ad12a1625f2ef1c52.zip
Merge branch 'master' into app
Conflicts: railties/lib/rails/application.rb
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb37
-rw-r--r--actionpack/lib/action_controller/base.rb23
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb36
-rw-r--r--actionpack/lib/action_view/base.rb14
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb8
-rw-r--r--actionpack/lib/action_view/helpers/cache_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb12
-rw-r--r--actionpack/lib/action_view/render/rendering.rb2
-rw-r--r--actionpack/test/abstract/render_test.rb35
9 files changed, 98 insertions, 71 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 826e82c8c6..a168b1b4c5 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -98,18 +98,9 @@ module AbstractController
_view_paths
end
- # Normalize options, by converting render "foo" to render :template => "foo"
- # and render "/foo" to render :file => "/foo".
- def _normalize_options(action=nil, options={})
- case action
- when Hash
- options, action = action, nil
- when String
- key = (action.index("/") == 0 ? :file : :template)
- options.merge!(key => action)
- end
-
- options
+ # The prefix used in render "foo" shortcuts.
+ def _prefix
+ controller_path
end
# Return a string representation of a Rack-compatible response body.
@@ -126,6 +117,28 @@ module AbstractController
private
+ # Normalize options, by converting render "foo" to render :template => "prefix/foo"
+ # and render "/foo" to render :file => "/foo".
+ def _normalize_options(action=nil, options={})
+ case action
+ when Hash
+ options, action = action, nil
+ when String, Symbol
+ action = action.to_s
+ case action.index("/")
+ when NilClass
+ options[:_prefix] = _prefix
+ options[:_template_name] = action
+ when 0
+ options[:file] = action
+ else
+ options[:template] = action
+ end
+ end
+
+ options
+ end
+
# Take in a set of options and determine the template to render
#
# ==== Options
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index a66aafd80e..f46231d72b 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -81,28 +81,5 @@ module ActionController
filter << block if block
filter
end
-
- def _normalize_options(action=nil, options={}, &blk)
- case action
- when NilClass
- when Hash, String
- options = super
- when Symbol
- options.merge! :action => action
- else
- options.merge! :partial => action
- end
-
- if options.key?(:action) && options[:action].to_s.index("/")
- options[:template] = options.delete(:action)
- end
-
- if options[:status]
- options[:status] = Rack::Utils.status_code(options[:status])
- end
-
- options[:update] = blk if block_given?
- options
- end
end
end
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 475ed54167..72e2bbd00e 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -25,18 +25,6 @@ module ActionController
end
private
- def _prefix
- controller_path
- end
-
- def _determine_template(options)
- if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
- options[:_template_name] ||= options[:action]
- options[:_prefix] = _prefix
- end
-
- super
- end
def _render_partial(options)
options[:partial] = action_name if options[:partial] == true
@@ -54,5 +42,29 @@ module ActionController
self.content_type = content_type if content_type
self.headers["Location"] = url_for(location) if location
end
+
+ def _normalize_options(action=nil, options={}, &blk)
+ case action
+ when NilClass
+ when Hash
+ options = super(action.delete(:action), action)
+ when String, Symbol
+ options = super
+ else
+ options.merge! :partial => action
+ end
+
+ if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
+ options[:_template_name] ||= options[:action]
+ options[:_prefix] = _prefix
+ end
+
+ if options[:status]
+ options[:status] = Rack::Utils.status_code(options[:status])
+ end
+
+ options[:update] = blk if block_given?
+ options
+ end
end
end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 4970c768e8..c4b0455c2a 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -181,7 +181,6 @@ module ActionView #:nodoc:
extend ActiveSupport::Memoizable
attr_accessor :base_path, :assigns, :template_extension, :formats
- attr_accessor :controller
attr_internal :captures
def reset_formats(formats)
@@ -277,13 +276,13 @@ module ActionView #:nodoc:
@config = nil
@formats = formats
@assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
- @controller = controller
+ @_controller = controller
@helpers = self.class.helpers || Module.new
@_content_for = Hash.new {|h,k| h[k] = ActionView::SafeBuffer.new }
self.view_paths = view_paths
end
- attr_internal :template
+ attr_internal :controller, :template
attr_reader :view_paths
def view_paths=(paths)
@@ -298,12 +297,11 @@ module ActionView #:nodoc:
# Evaluates the local assigns and controller ivars, pushes them to the view.
def _evaluate_assigns_and_ivars #:nodoc:
- if @controller
- variables = @controller.instance_variable_names
- variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
- variables.each { |name| instance_variable_set(name, @controller.instance_variable_get(name)) }
+ if controller
+ variables = controller.instance_variable_names
+ variables -= controller.protected_instance_variables if controller.respond_to?(:protected_instance_variables)
+ variables.each { |name| instance_variable_set(name, controller.instance_variable_get(name)) }
end
end
-
end
end
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 15b70ecff5..83357dd76f 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -634,8 +634,8 @@ module ActionView
# Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL
# roots. Rewrite the asset path for cache-busting asset ids. Include
# asset host, if configured, with the correct request protocol.
- def compute_public_path(source, dir, ext = nil, include_host = true)
- has_request = @controller.respond_to?(:request)
+ def compute_public_path(source, dir, ext = nil, include_host = true)
+ has_request = controller.respond_to?(:request)
source_ext = File.extname(source)[1..-1]
if ext && !is_uri?(source) && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}"))))
@@ -658,7 +658,7 @@ module ActionView
host = compute_asset_host(source)
if has_request && !host.blank? && !is_uri?(host)
- host = "#{@controller.request.protocol}#{host}"
+ host = "#{controller.request.protocol}#{host}"
end
"#{host}#{source}"
@@ -681,7 +681,7 @@ module ActionView
if host.is_a?(Proc) || host.respond_to?(:call)
case host.is_a?(Proc) ? host.arity : host.method(:call).arity
when 2
- request = @controller.respond_to?(:request) && @controller.request
+ request = controller.respond_to?(:request) && controller.request
host.call(source, request)
else
host.call(source)
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb
index 64d1ad2715..d5cc14b29a 100644
--- a/actionpack/lib/action_view/helpers/cache_helper.rb
+++ b/actionpack/lib/action_view/helpers/cache_helper.rb
@@ -32,7 +32,7 @@ module ActionView
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- @controller.fragment_for(output_buffer, name, options, &block)
+ controller.fragment_for(output_buffer, name, options, &block)
end
end
end
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 14628c5404..511386fede 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -13,7 +13,7 @@ module ActionView
# Need to map default url options to controller one.
def default_url_options(*args) #:nodoc:
- @controller.send(:default_url_options, *args)
+ controller.send(:default_url_options, *args)
end
# Returns the URL for the set of +options+ provided. This takes the
@@ -89,10 +89,10 @@ module ActionView
when Hash
options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
escape = options.key?(:escape) ? options.delete(:escape) : false
- @controller.send(:url_for, options)
+ controller.send(:url_for, options)
when :back
escape = false
- @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
+ controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
else
escape = false
polymorphic_path(options)
@@ -546,10 +546,10 @@ module ActionView
# # => false
def current_page?(options)
url_string = CGI.unescapeHTML(url_for(options))
- request = @controller.request
- # We ignore any extra parameters in the request_uri if the
+ request = controller.request
+ # We ignore any extra parameters in the request_uri if the
# submitted url doesn't have any either. This lets the function
- # work with things like ?order=asc
+ # work with things like ?order=asc
if url_string.index("?")
request_uri = request.request_uri
else
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index ec278ca783..7c33f1334a 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/try'
+
module ActionView
module Rendering
# Returns the result of a render that's dictated by the options hash. The primary options are:
diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb
index 4bec44c9ae..ffd430fa86 100644
--- a/actionpack/test/abstract/render_test.rb
+++ b/actionpack/test/abstract/render_test.rb
@@ -6,9 +6,16 @@ module AbstractController
class ControllerRenderer < AbstractController::Base
include AbstractController::Rendering
+ def _prefix
+ "renderer"
+ end
+
self.view_paths = [ActionView::FixtureResolver.new(
"default.erb" => "With Default",
"template.erb" => "With Template",
+ "renderer/string.erb" => "With String",
+ "renderer/symbol.erb" => "With Symbol",
+ "string/with_path.erb" => "With String With Path",
"some/file.erb" => "With File",
"template_name.erb" => "With Template Name"
)]
@@ -33,8 +40,16 @@ module AbstractController
render
end
- def shortcut
- render "template"
+ def string
+ render "string"
+ end
+
+ def string_with_path
+ render "string/with_path"
+ end
+
+ def symbol
+ render :symbol
end
def template_name
@@ -77,9 +92,19 @@ module AbstractController
assert_equal "With Default", @controller.response_body
end
- def test_render_template_through_shortcut
- @controller.process(:shortcut)
- assert_equal "With Template", @controller.response_body
+ def test_render_string
+ @controller.process(:string)
+ assert_equal "With String", @controller.response_body
+ end
+
+ def test_render_symbol
+ @controller.process(:symbol)
+ assert_equal "With Symbol", @controller.response_body
+ end
+
+ def test_render_string_with_path
+ @controller.process(:string_with_path)
+ assert_equal "With String With Path", @controller.response_body
end
def test_render_template_name