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...

This commit is contained in:
Carlhuda
2010-03-01 14:37:05 -08:00
parent 8fbbdda526
commit b85ea58eb5
6 changed files with 31 additions and 19 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -9,6 +9,7 @@ class JavaScriptHelperTest < ActionView::TestCase
def reset_formats(format)
@format = format
yield if block_given?
end
def setup

View File

@@ -41,6 +41,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase
def reset_formats(format)
@format = format
yield if block_given?
end
def setup