From 55ee0ba7f5b6b5d2023eb5dcc030946ed589fe53 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Wed, 17 Jun 2009 16:23:11 -0700 Subject: Cleaning up if defined?(ActionController::Http) blocks from the pre new base era. --- actionpack/lib/action_controller/base/flash.rb | 53 +++++++++------------- actionpack/lib/action_controller/base/streaming.rb | 5 +- .../lib/action_controller/base/verification.rb | 1 - .../lib/action_controller/caching/actions.rb | 17 ++----- actionpack/lib/action_view/base.rb | 52 ++++++--------------- actionpack/lib/action_view/render/rendering.rb | 1 - .../lib/action_view/template/handlers/builder.rb | 3 +- 7 files changed, 42 insertions(+), 90 deletions(-) diff --git a/actionpack/lib/action_controller/base/flash.rb b/actionpack/lib/action_controller/base/flash.rb index cac14175d9..590f9be3ac 100644 --- a/actionpack/lib/action_controller/base/flash.rb +++ b/actionpack/lib/action_controller/base/flash.rb @@ -28,13 +28,7 @@ module ActionController #:nodoc: module Flash extend ActiveSupport::Concern - # TODO : Remove the defined? check when new base is the main base - include Session if defined?(ActionController::Http) - - included do - # TODO : Remove the defined? check when new base is the main base - include InstanceMethods - end + include Session class FlashNow #:nodoc: def initialize(flash) @@ -141,33 +135,30 @@ module ActionController #:nodoc: end end - module InstanceMethods #:nodoc: - protected - def process_action(method_name) - super - if defined? @_flash - @_flash.store(session) - remove_instance_variable(:@_flash) - end - end - - def reset_session - super - remove_instance_variable(:@_flash) if defined?(@_flash) - end + protected + def process_action(method_name) + super + if defined? @_flash + @_flash.store(session) + remove_instance_variable(:@_flash) + end end - protected - # Access the contents of the flash. Use flash["notice"] to - # read a notice you put there or flash["notice"] = "hello" - # to put a new one. - def flash #:doc: - if !defined?(@_flash) - @_flash = session["flash"] || FlashHash.new - @_flash.sweep - end + def reset_session + super + remove_instance_variable(:@_flash) if defined?(@_flash) + end - @_flash + # Access the contents of the flash. Use flash["notice"] to + # read a notice you put there or flash["notice"] = "hello" + # to put a new one. + def flash #:doc: + if !defined?(@_flash) + @_flash = session["flash"] || FlashHash.new + @_flash.sweep end + + @_flash + end end end diff --git a/actionpack/lib/action_controller/base/streaming.rb b/actionpack/lib/action_controller/base/streaming.rb index 5c72fc9ad9..70a97ccfec 100644 --- a/actionpack/lib/action_controller/base/streaming.rb +++ b/actionpack/lib/action_controller/base/streaming.rb @@ -4,10 +4,7 @@ module ActionController #:nodoc: module Streaming extend ActiveSupport::Concern - # TODO : Remove the defined? check when new base is the main base - if defined?(ActionController::Http) - include ActionController::Renderer - end + include ActionController::Renderer DEFAULT_SEND_FILE_OPTIONS = { :type => 'application/octet-stream'.freeze, diff --git a/actionpack/lib/action_controller/base/verification.rb b/actionpack/lib/action_controller/base/verification.rb index 7190b6b106..951ae1bee1 100644 --- a/actionpack/lib/action_controller/base/verification.rb +++ b/actionpack/lib/action_controller/base/verification.rb @@ -2,7 +2,6 @@ module ActionController #:nodoc: module Verification #:nodoc: extend ActiveSupport::Concern - # TODO : Remove the defined? check when new base is the main base include AbstractController::Callbacks, Session, Flash, Renderer # This module provides a class-level method for specifying that certain diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 4420678df6..d8a1662acc 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -84,19 +84,10 @@ module ActionController #:nodoc: @options = options end - # TODO: Remove once New Base is merged - if defined?(ActionController::Http) - def filter(controller) - should_continue = before(controller) - yield if should_continue - after(controller) - end - else - def filter(controller, action) - should_continue = before(controller) - action.call if should_continue - after(controller) - end + def filter(controller) + should_continue = before(controller) + yield if should_continue + after(controller) end def before(controller) diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 2d8f51300a..1ca6f839a8 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -230,39 +230,24 @@ module ActionView #:nodoc: def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil, formats = nil)#:nodoc: @formats = formats || [:html] @assigns = assigns_for_first_render - @assigns_added = nil @controller = controller @helpers = ProxyModule.new(self) self.view_paths = view_paths - - @_first_render = nil - @_current_render = nil end + attr_internal :template attr_reader :view_paths def view_paths=(paths) @view_paths = self.class.process_view_paths(paths) end - # Access the current template being rendered. - # Returns a ActionView::Template object. - def template - @_current_render - end - - def template=(template) #:nodoc: - @_first_render ||= template - @_current_render = template - end - def with_template(current_template) last_template, self.template = template, current_template - old_formats, self.formats = formats, [current_template.mime_type.to_sym] + Mime::SET.symbols + last_formats, self.formats = formats, [current_template.mime_type.to_sym] + Mime::SET.symbols yield ensure - self.template = last_template - self.formats = old_formats + self.template, self.formats = last_template, last_formats end def punctuate_body!(part) @@ -273,30 +258,21 @@ module ActionView #:nodoc: # Evaluates the local assigns and controller ivars, pushes them to the view. def _evaluate_assigns_and_ivars #:nodoc: - unless @assigns_added - @assigns.each { |key, value| instance_variable_set("@#{key}", value) } - _copy_ivars_from_controller - @assigns_added = true - end + return if @assigns_added + @assigns.each { |key, value| instance_variable_set("@#{key}", value) } + _copy_ivars_from_controller + @assigns_added = true end - private + private - def _copy_ivars_from_controller #: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)) } - end + def _copy_ivars_from_controller #: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)) } end + end - def _set_controller_content_type(content_type) #:nodoc: - # TODO: Remove this method when new base is switched - unless defined?(ActionController::Http) - if controller.respond_to?(:response) - controller.response.content_type ||= content_type - end - end - end end end diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index fe785e7b20..d120631e5d 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -64,7 +64,6 @@ module ActionView def _render_template(template, local_assigns = {}) with_template(template) do _evaluate_assigns_and_ivars - _set_controller_content_type(template.mime_type) if template.respond_to?(:mime_type) template.render(self, local_assigns) do |*names| if !instance_variable_defined?(:"@content_for_#{names.first}") && diff --git a/actionpack/lib/action_view/template/handlers/builder.rb b/actionpack/lib/action_view/template/handlers/builder.rb index f412228752..abe140af0b 100644 --- a/actionpack/lib/action_view/template/handlers/builder.rb +++ b/actionpack/lib/action_view/template/handlers/builder.rb @@ -8,8 +8,7 @@ module ActionView self.default_format = Mime::XML def compile(template) - "_set_controller_content_type(Mime::XML);" + - "xml = ::Builder::XmlMarkup.new(:indent => 2);" + + "xml = ::Builder::XmlMarkup.new(:indent => 2);" + "self.output_buffer = xml.target!;" + template.source + ";xml.target!;" -- cgit v1.2.3