Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/action_view/template/handlers/rjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ module Template::Handlers
class RJS
# Default format used by RJS.
class_attribute :default_format
self.default_format = Mime::JS
self.default_format = Mime[:js]

def call(template)
"update_page do |page|;#{template.source}\nend"
if Rails::VERSION::MAJOR >= 6
def call(template, source)
"update_page do |page|;#{source}\nend"
end
end

if Rails::VERSION::MAJOR == 5
def call(template)
"update_page do |page|;#{template.source}\nend"
end
end
end
end
Expand Down
10 changes: 3 additions & 7 deletions lib/prototype-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

module PrototypeRails
class Engine < Rails::Engine
initializer 'prototype-rails.initialize' do
ActiveSupport.on_load(:action_controller) do
require 'prototype-rails/on_load_action_controller'
end
config.after_initialize do
require 'prototype-rails/on_load_action_controller'

ActiveSupport.on_load(:action_view) do
require 'prototype-rails/on_load_action_view'
end
require 'prototype-rails/on_load_action_view'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prototype-rails/renderers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Renderers
add :update do |proc, options|
view_context = self.view_context
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
self.content_type = Mime::JS
self.content_type = Mime[:js]
self.response_body = generator.to_s
end
end
Expand Down
28 changes: 21 additions & 7 deletions lib/prototype-rails/rendering.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
require 'action_view/helpers/rendering_helper'

ActionView::Helpers::RenderingHelper.module_eval do
def render_with_update(options = {}, locals = {}, &block)
if options == :update
update_page(&block)
else
render_without_update(options, locals, &block)
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 0
module RenderWithUpdate
def render(options = {}, locals = {}, &block)
if options == :update
update_page(&block)
else
super(options, locals, &block)
end
end
end

prepend RenderWithUpdate
else
def render_with_update(options = {}, locals = {}, &block)
if options == :update
update_page(&block)
else
render_without_update(options, locals, &block)
end
end

alias_method_chain :render, :update
end

alias_method_chain :render, :update
end
10 changes: 5 additions & 5 deletions lib/prototype-rails/selector_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'active_support/core_ext/module/aliasing'
require 'action_view/vendor/html-scanner'
require 'action_dispatch/testing/assertions'
require 'action_dispatch/testing/assertions/selector'
require 'rails/dom/testing/assertions/selector_assertions'

#--
# Copyright (c) 2006 Assaf Arkin (http://labnotes.org)
# Under MIT and/or CC By license.
#++

ActionDispatch::Assertions::SelectorAssertions.module_eval do
module PrototypeRails
module SelectorAssertions
# Selects content from the RJS response.
#
# === Narrowing down
Expand Down Expand Up @@ -174,7 +174,7 @@ def assert_select_rjs(*args, &block)
def response_from_page_with_rjs
content_type = @response.content_type

if content_type && Mime::JS =~ content_type
if content_type && Mime[:js] =~ content_type
body = @response.body.dup
root = HTML::Node.new(nil)

Expand All @@ -193,7 +193,6 @@ def response_from_page_with_rjs
response_from_page_without_rjs
end
end
alias_method_chain :response_from_page, :rjs

# Unescapes a RJS string.
def unescape_rjs(rjs_string)
Expand All @@ -208,3 +207,4 @@ def unescape_rjs(rjs_string)
unescaped
end
end
end
4 changes: 2 additions & 2 deletions prototype-rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Gem::Specification.new do |spec|
spec.name = 'prototype-rails'
spec.version = '4.0.0'
spec.version = '4.2.1'
spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails'
spec.homepage = 'http://github.com/rails/prototype-rails'
spec.author = 'Xavier Noria'
spec.email = 'fxn@hashref.com'

spec.files = %w(README.md Rakefile Gemfile MIT-LICENSE) + Dir['lib/**/*', 'vendor/**/*', 'test/**/*']

spec.add_dependency('rails', '~> 4.0')
spec.add_dependency('rails')
spec.add_development_dependency('mocha')
spec.license = "MIT"
end
2 changes: 1 addition & 1 deletion test/controller/content_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ContentTypeTest < ActionController::TestCase

def test_default_for_rjs
xhr :post, :render_default_for_rjs
assert_equal Mime::JS, @response.content_type
assert_equal Mime[:js], @response.content_type
assert_equal "utf-8", @response.charset
end
end
2 changes: 1 addition & 1 deletion test/controller/mime_responds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def resource
end

def _render_js(js, options)
self.content_type ||= Mime::JS
self.content_type ||= Mime[:js]
self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/render_other_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'securerandom'

ActionController.add_renderer :simon do |says, options|
self.content_type = Mime::TEXT
self.content_type = Mime[:text]
self.response_body = "Simon says: #{says}"
end

Expand Down