Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 6.0 Support #46

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e7fa1fe
config.action_view.debug_rjs was removed
korny Jun 10, 2011
d7c0042
start on 4.2 support
tenderlove Nov 14, 2014
bfec473
Merge branch 'master' into 4.2
Jan 27, 2015
305fca4
Fixed deprecation warning "ActionDispatch::Assertions::SelectorAssert…
Mar 11, 2015
0fed929
Merge pull request #36 from Nike0/4.2
rafaelfranca Mar 12, 2015
eb9632d
Update to allow Rails 5
Mar 13, 2017
04c4dea
Fix deprecation
Mar 13, 2017
0bdf18d
Fix deprecated reference
Mar 20, 2017
decebc3
Move to Module#prepend in prep for for Rails 5.1
Apr 6, 2017
45e4852
update_page fragments are marked as html_safe even though they have n…
esb Jan 11, 2013
8ddd03c
include the X-CSRF-Token header with every Ajax request
esb Jan 12, 2013
b7718ba
Reapply the actionpack 2.2 fix for disable-with, the original submit …
esb Jan 12, 2013
524b86a
Make click event handler on a elements only respond to left clicks
esb Jan 13, 2013
98db453
Ensure onclick handlers are escaped only once
esb Jan 15, 2013
d554af6
Update rails gem
May 22, 2017
9f639a3
Don't disable *every* submit field, just the one that has been clicked
May 22, 2017
a2fbb9c
Passed along any original 'target' attribute to the generated form ta…
Jun 15, 2017
2f58665
CI-1376 Get rid of disableFormElements content
Aug 3, 2017
3902627
Revert "CI-1376 Get rid of disableFormElements content"
binary-koan Aug 13, 2017
d07c95b
CI-1614 Restore disabling of form submit buttons
binary-koan Aug 13, 2017
e7f8e04
Merge pull request #3 from fluxfederation/ci-1614
binary-koan Nov 20, 2017
07b2003
Merge remote-tracking branch 'upstream/master'
korny Apr 11, 2022
f570d7f
Merge remote-tracking branch 'fluxfederation/rails-5.0' into rails-6.0
korny Apr 11, 2022
c96372e
tweaks for Rails 6.0
korny Apr 11, 2022
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
166 changes: 98 additions & 68 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,119 @@ PATH
remote: .
specs:
prototype-rails (4.0.0)
rails (~> 4.0)
rails (>= 4.0)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.0)
actionpack (= 4.0.0)
mail (~> 2.5.3)
actionpack (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activerecord (4.0.0)
activemodel (= 4.0.0)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.0)
atomic (1.1.13)
builder (3.1.4)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.5)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
actioncable (5.1.1)
actionpack (= 5.1.1)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.1)
actionview (= 5.1.1)
activesupport (= 5.1.1)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.1)
activesupport (= 5.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.1)
activesupport (= 5.1.1)
globalid (>= 0.3.6)
activemodel (5.1.1)
activesupport (= 5.1.1)
activerecord (5.1.1)
activemodel (= 5.1.1)
activesupport (= 5.1.1)
arel (~> 8.0)
activesupport (5.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
builder (3.2.3)
concurrent-ruby (1.0.5)
erubi (1.6.0)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.1)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.5)
mime-types (>= 1.16, < 4)
metaclass (0.0.1)
mime-types (1.24)
minitest (4.7.5)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.2)
mocha (0.10.3)
metaclass (~> 0.0.1)
multi_json (1.7.9)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
nio4r (2.0.0)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
rack (2.0.3)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.0.0)
actionmailer (= 4.0.0)
actionpack (= 4.0.0)
activerecord (= 4.0.0)
activesupport (= 4.0.0)
rails (5.1.1)
actioncable (= 5.1.1)
actionmailer (= 5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
activemodel (= 5.1.1)
activerecord (= 5.1.1)
activesupport (= 5.1.1)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.0)
sprockets-rails (~> 2.0.0)
railties (4.0.0)
actionpack (= 4.0.0)
activesupport (= 4.0.0)
railties (= 5.1.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.1)
actionpack (= 5.1.1)
activesupport (= 5.1.1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
sprockets (2.10.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
thor (0.18.1)
thread_safe (0.1.2)
atomic
tilt (1.4.1)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
rake (12.0.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.4)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)

PLATFORMS
ruby

DEPENDENCIES
mocha
prototype-rails!

BUNDLED WITH
1.14.6
2 changes: 1 addition & 1 deletion lib/action_view/helpers/prototype_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def method_missing(method, *arguments)
# page.hide 'spinner'
# end
def update_page(&block)
JavaScriptGenerator.new(self, &block).to_s.html_safe
JavaScriptGenerator.new(self, &block).to_s
end

# Works like update_page but wraps the generated JavaScript in a
Expand Down
4 changes: 2 additions & 2 deletions lib/action_view/template/handlers/rjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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)
def call(template, source = template.source)
"update_page do |page|;#{template.source}\nend"
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/prototype-rails/javascript_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def button_to_function(name, *args, &block)
function = block_given? ? update_page(&block) : args[0] || ''
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};"

tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick))
tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => escape_once(onclick)), false, false)
end

# link_to_function("Show me more", nil, :id => "more_link") do |page|
Expand All @@ -62,6 +62,6 @@ def link_to_function(name, *args, &block)
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
href = html_options[:href] || '#'

content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
content_tag(:a, name, html_options.merge(:href => href, :onclick => escape_once(onclick)), false)
end
end
8 changes: 5 additions & 3 deletions lib/prototype-rails/on_load_action_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
end

if defined?(Rails.env) && Rails.env.test?
ActionView::TestCase.class_eval do
include ActionView::Helpers::PrototypeHelper
include ActionView::Helpers::ScriptaculousHelper
ActiveSupport::Reloader.to_prepare do
ActionView::TestCase.class_eval do
include ActionView::Helpers::PrototypeHelper
include ActionView::Helpers::ScriptaculousHelper
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
21 changes: 11 additions & 10 deletions lib/prototype-rails/rendering.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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)
end
module PrototypeRails
module Rendering
def render(options = {}, locals = {}, &block)
if options == :update
update_page(&block)
else
super(options, locals, &block)
end
end
end

alias_method_chain :render, :update
end
end
ActionView::Helpers::RenderingHelper.send(:prepend, PrototypeRails::Rendering)
8 changes: 4 additions & 4 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 @@ -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
2 changes: 1 addition & 1 deletion prototype-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |spec|

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

spec.add_dependency('rails', '~> 4.0')
spec.add_dependency('rails', '>= 4.0')
spec.add_development_dependency('mocha')
spec.license = "MIT"
end
12 changes: 12 additions & 0 deletions test/template/prototype_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ def test_update_page_tag_with_html_options
assert_equal javascript_tag(create_generator(&block).to_s, {:defer => 'true'}), update_page_tag({:defer => 'true'}, &block)
end

def test_update_page_html_tag
block = Proc.new { |page| page.hide('cancel-commit') }
input_tag = submit_tag('Save', :onclick => 'Element.hide("cancel-commit");')
assert_equal input_tag, submit_tag('Save', :onclick => update_page(&block))
end

def test_update_page_link_to_function
block = Proc.new { |page| page.hide('cancel-commit') }
link_tag = link_to_function('Save', 'Element.hide("cancel-commit");')
assert_equal link_tag, link_to_function('Save', update_page(&block))
end

def test_remote_function
res = remote_function(:url => authors_path, :with => "'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')")
assert_equal "new Ajax.Request('/authors', {asynchronous:true, evalScripts:true, parameters:'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')})", res
Expand Down
Loading