Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the :rjs render option

  • Loading branch information...
commit 6923b392b740f2346326634532b40cf24a0f26ef 1 parent e773d0e
Yehuda Katz + Carl Lerche authored
14 actionpack/lib/action_controller/new_base/base.rb
View
@@ -13,6 +13,7 @@ class Base < Http
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 @@ def self.app_loaded!
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 @@ def _normalize_options(action = nil, options = {})
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
11 actionpack/lib/action_controller/new_base/render_options.rb
View
@@ -71,5 +71,16 @@ def _render_xml(xml, options)
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
17 actionpack/lib/action_view/base.rb
View
@@ -269,15 +269,16 @@ def punctuate_body!(part)
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
2  actionpack/lib/action_view/helpers/prototype_helper.rb
View
@@ -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 @@ def observe_form(form_id, options = {})
# #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
1  actionpack/lib/action_view/template/handler.rb
View
@@ -1,4 +1,5 @@
require "active_support/core_ext/class/inheritable_attributes"
+require "action_dispatch/http/mime_type"
# Legacy TemplateHandler stub
module ActionView
8 actionpack/test/controller/render_other_test.rb
View
@@ -103,6 +103,14 @@ def render_alternate_default
end
private
+ def default_render
+ if @alternate_default_render
+ @alternate_default_render.call
+ else
+ super
+ end
+ end
+
def determine_layout
case action_name
when "render_js_with_explicit_template",
4 actionpack/test/template/javascript_helper_test.rb
View
@@ -3,6 +3,8 @@
class JavaScriptHelperTest < ActionView::TestCase
tests ActionView::Helpers::JavaScriptHelper
+ def _evaluate_assigns_and_ivars() end
+
attr_accessor :formats, :output_buffer
def setup
@@ -10,6 +12,8 @@ def setup
@template = self
end
+ def _evaluate_assigns_and_ivars() end
+
def test_escape_javascript
assert_equal '', escape_javascript(nil)
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
4 actionpack/test/template/prototype_helper_test.rb
View
@@ -61,6 +61,8 @@ def create_generator
end
class PrototypeHelperTest < PrototypeHelperBaseTest
+ def _evaluate_assigns_and_ivars() end
+
def setup
@record = @author = Author.new
@article = Article.new
@@ -304,6 +306,8 @@ def setup
@generator = create_generator
end
+ def _evaluate_assigns_and_ivars() end
+
def test_insert_html_with_string
assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });',
@generator.insert_html(:top, 'element', '<p>This is a test</p>')
Please sign in to comment.
Something went wrong with that request. Please try again.