Permalink
Browse files

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...
  • Loading branch information...
1 parent 8fbbdda commit b85ea58eb561d0a0fd2b0a3dbae1dc7846961c2d Carlhuda committed Mar 1, 2010
@@ -52,7 +52,7 @@ def default_render
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
@@ -23,10 +23,14 @@ def render(*args)
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
@@ -182,14 +182,12 @@ class JavaScriptGenerator #:nodoc:
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 @@ def record(line)
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)
@@ -25,7 +25,7 @@ def render(options = {}, locals = {}, &block) #:nodoc:
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 @@ def render(options = {}, locals = {}, &block) #:nodoc:
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 @@ def render(options = {}, locals = {}, &block) #:nodoc:
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
@@ -9,6 +9,7 @@ def _evaluate_assigns_and_ivars() end
def reset_formats(format)
@format = format
+ yield if block_given?
end
def setup
@@ -41,6 +41,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase
def reset_formats(format)
@format = format
+ yield if block_given?
end
def setup

0 comments on commit b85ea58

Please sign in to comment.