aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-01 14:37:05 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-03-01 14:37:05 -0800
commitb85ea58eb561d0a0fd2b0a3dbae1dc7846961c2d (patch)
treecd6aff630ea6d1ebcbfde508fb35b8b4a1d8118b /actionpack
parent8fbbdda52634991b047b7567fe3a8ec7c9a6c558 (diff)
downloadrails-b85ea58eb561d0a0fd2b0a3dbae1dc7846961c2d.tar.gz
rails-b85ea58eb561d0a0fd2b0a3dbae1dc7846961c2d.tar.bz2
rails-b85ea58eb561d0a0fd2b0a3dbae1dc7846961c2d.zip
Change AV formats so they can delegate to the controller. Now users (or plugins) can override details_for_render in their controllers and add appropriate additional details. Now if only they could *do* something with those details...
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb6
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb32
-rw-r--r--actionpack/lib/action_view/render/rendering.rb8
-rw-r--r--actionpack/test/template/javascript_helper_test.rb1
-rw-r--r--actionpack/test/template/prototype_helper_test.rb1
6 files changed, 31 insertions, 19 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index f8ddc8da09..13139358c7 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -52,7 +52,7 @@ module ActionController
def method_for_action(action_name)
super || begin
- if view_paths.exists?(action_name.to_s, {:formats => formats}, controller_path)
+ if view_paths.exists?(action_name.to_s, details_for_render, controller_path)
"default_render"
end
end
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index a026289ee5..6e5379745b 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -23,10 +23,14 @@ module ActionController
def _render_partial(options)
options[:partial] = action_name if options[:partial] == true
- options[:_details] = {:formats => formats}
+ options[:_details] = details_for_render
super
end
+ def details_for_render
+ {:formats => formats}
+ end
+
def format_for_text
formats.first
end
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 3c4511d931..67a7586699 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -182,14 +182,12 @@ module ActionView
def initialize(context, &block) #:nodoc:
context._evaluate_assigns_and_ivars
@context, @lines = context, []
- old_formats = @context.formats
- @context.reset_formats([:js, :html]) if @context
- include_helpers_from_context
- @context.with_output_buffer(@lines) do
- @context.instance_exec(self, &block)
+ @context.reset_formats([:js, :html]) do
+ include_helpers_from_context
+ @context.with_output_buffer(@lines) do
+ @context.instance_exec(self, &block)
+ end
end
- ensure
- @context.reset_formats(old_formats) if @context
end
private
@@ -573,15 +571,19 @@ module ActionView
end
end
- def render(*options_for_render)
- old_formats = @context && @context.formats
+ def render(*options)
+ with_formats(:html) do
+ case option = options.first
+ when Hash
+ @context.render(*options)
+ else
+ option.to_s
+ end
+ end
+ end
- @context.reset_formats([:html]) if @context
- Hash === options_for_render.first ?
- @context.render(*options_for_render) :
- options_for_render.first.to_s
- ensure
- @context.reset_formats(old_formats) if @context
+ def with_formats(*args)
+ @context ? @context.reset_formats(args) { yield } : yield
end
def javascript_object_for(object)
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index abc7c09991..64cc0caf11 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -25,7 +25,7 @@ module ActionView
end
template = if options[:file]
- find(options[:file], {:formats => formats})
+ find(options[:file], details_for_render)
elsif options[:inline]
handler = Template.handler_class_for_extension(options[:type] || "erb")
Template.new(options[:inline], "inline template", handler, {})
@@ -34,7 +34,7 @@ module ActionView
end
if template
- layout = find(layout, {:formats => formats}) if layout
+ layout = find(layout, details_for_render) if layout
_render_template(template, layout, :locals => options[:locals])
end
when :update
@@ -44,6 +44,10 @@ module ActionView
end
end
+ def details_for_render
+ controller.try(:details_for_render) || {:formats => formats}
+ end
+
# You can think of a layout as a method that is called with a block. _layout_for
# returns the contents that are yielded to the layout. If the user calls yield
# :some_name, the block, by default, returns content_for(:some_name). If the user
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index b3e7abc387..368a9c2514 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -9,6 +9,7 @@ class JavaScriptHelperTest < ActionView::TestCase
def reset_formats(format)
@format = format
+ yield if block_given?
end
def setup
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index 45f9d85e32..6811d3aaf3 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -41,6 +41,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase
def reset_formats(format)
@format = format
+ yield if block_given?
end
def setup