Delegate formats to the controller
This commit is contained in:
parent
2060977b76
commit
8fbbdda526
|
@ -186,12 +186,21 @@ module ActionView #:nodoc:
|
|||
|
||||
extend ActiveSupport::Memoizable
|
||||
|
||||
attr_accessor :base_path, :assigns, :template_extension, :formats
|
||||
attr_accessor :base_path, :assigns, :template_extension
|
||||
attr_internal :captures
|
||||
|
||||
def reset_formats(formats)
|
||||
@formats = formats
|
||||
old_formats, self.formats = self.formats, formats
|
||||
reset_hash_key
|
||||
yield if block_given?
|
||||
ensure
|
||||
if block_given?
|
||||
self.formats = old_formats
|
||||
reset_hash_key
|
||||
end
|
||||
end
|
||||
|
||||
def reset_hash_key
|
||||
if defined?(AbstractController::HashKey)
|
||||
# This is expensive, but we need to reset this when the format is updated,
|
||||
# which currently only happens
|
||||
|
@ -200,6 +209,18 @@ module ActionView #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
def formats
|
||||
controller ? controller.formats : @formats
|
||||
end
|
||||
|
||||
def formats=(val)
|
||||
if controller
|
||||
controller.formats = val
|
||||
else
|
||||
@formats = val
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB'
|
||||
delegate :logger, :to => 'ActionController::Base', :allow_nil => true
|
||||
|
|
|
@ -182,10 +182,14 @@ 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)
|
||||
end
|
||||
ensure
|
||||
@context.reset_formats(old_formats) if @context
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in New Issue