From 6923b392b740f2346326634532b40cf24a0f26ef Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 21 May 2009 16:35:40 -0700 Subject: Added the :rjs render option --- actionpack/lib/action_controller/new_base/base.rb | 14 ++++++++------ .../lib/action_controller/new_base/render_options.rb | 11 +++++++++++ actionpack/lib/action_view/base.rb | 17 +++++++++-------- actionpack/lib/action_view/helpers/prototype_helper.rb | 2 ++ actionpack/lib/action_view/template/handler.rb | 1 + 5 files changed, 31 insertions(+), 14 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 034e614d6e..fae08c58b2 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -13,6 +13,7 @@ module ActionController include ActionController::Renderer include ActionController::Renderers::Json include ActionController::Renderers::Xml + include ActionController::Renderers::Rjs include ActionController::Layouts include ActionController::ConditionalGet @@ -74,7 +75,7 @@ module ActionController end end - def _normalize_options(action = nil, options = {}) + def _normalize_options(action = nil, options = {}, &blk) if action.is_a?(Hash) options, action = action, nil elsif action.is_a?(String) || action.is_a?(Symbol) @@ -93,19 +94,20 @@ module ActionController end if options[:status] - options[:status] = interpret_status(options.delete(:status)).to_i + options[:status] = interpret_status(options[:status]).to_i end + options[:update] = blk if block_given? options end - def render(action = nil, options = {}) - options = _normalize_options(action, options) + def render(action = nil, options = {}, &blk) + options = _normalize_options(action, options, &blk) super(options) end - def render_to_string(action = nil, options = {}) - options = _normalize_options(action, options) + def render_to_string(action = nil, options = {}, &blk) + options = _normalize_options(action, options, &blk) super(options) end diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb index aa6593b957..1df23deee7 100644 --- a/actionpack/lib/action_controller/new_base/render_options.rb +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -71,5 +71,16 @@ module ActionController self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml end end + + module Rjs + include RenderOption + register_renderer :update + + def _render_update(proc, options) + generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(_action_view, &proc) + response.content_type = Mime::JS + self.response_body = generator.to_s + end + end end end \ No newline at end of file diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 6b72d406af..4ab568b44c 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -269,15 +269,16 @@ module ActionView #:nodoc: nil end - private - # 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 + # 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 + end + + private def _copy_ivars_from_controller #:nodoc: if @controller diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 1fbe012a95..c0f5df3468 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -1,5 +1,6 @@ require 'set' require 'active_support/json' +require 'active_support/core_ext/object/extending' module ActionView module Helpers @@ -572,6 +573,7 @@ module ActionView # #include_helpers_from_context has nothing to overwrite. class JavaScriptGenerator #:nodoc: def initialize(context, &block) #:nodoc: + context._evaluate_assigns_and_ivars @context, @lines = context, [] include_helpers_from_context @context.with_output_buffer(@lines) do diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb index 3481a4a4e7..3071c78174 100644 --- a/actionpack/lib/action_view/template/handler.rb +++ b/actionpack/lib/action_view/template/handler.rb @@ -1,4 +1,5 @@ require "active_support/core_ext/class/inheritable_attributes" +require "action_dispatch/http/mime_type" # Legacy TemplateHandler stub module ActionView -- cgit v1.2.3