remotipart 1.2.1 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +35 -0
  3. data/Appraisals +25 -0
  4. data/Gemfile +14 -1
  5. data/History.rdoc +34 -0
  6. data/LICENSE +4 -0
  7. data/README.rdoc +35 -8
  8. data/Rakefile +5 -7
  9. data/gemfiles/rails_3.2.gemfile +26 -0
  10. data/gemfiles/rails_4.2.gemfile +24 -0
  11. data/gemfiles/rails_5.2.gemfile +24 -0
  12. data/gemfiles/rails_6.0.gemfile +24 -0
  13. data/lib/remotipart/middleware.rb +9 -4
  14. data/lib/remotipart/rails/engine.rb +15 -5
  15. data/lib/remotipart/rails/railtie.rb +8 -4
  16. data/lib/remotipart/rails/version.rb +2 -2
  17. data/lib/remotipart/render_overrides.rb +29 -7
  18. data/lib/remotipart/request_helper.rb +2 -0
  19. data/lib/remotipart/view_helper.rb +2 -0
  20. data/remotipart.gemspec +95 -19
  21. data/spec/dummy_app/.gitignore +17 -0
  22. data/spec/dummy_app/Rakefile +7 -0
  23. data/spec/dummy_app/app/assets/config/manifest.js +4 -0
  24. data/spec/dummy_app/app/assets/images/rails.png +0 -0
  25. data/spec/dummy_app/app/assets/javascripts/application.js.erb +8 -0
  26. data/spec/dummy_app/app/assets/javascripts/comments.js +28 -0
  27. data/spec/dummy_app/app/assets/stylesheets/application.css +6 -0
  28. data/spec/dummy_app/app/assets/stylesheets/scaffold.css +65 -0
  29. data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
  30. data/spec/dummy_app/app/controllers/comments_controller.rb +72 -0
  31. data/spec/dummy_app/app/controllers/prepended_controller.rb +9 -0
  32. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy_app/app/helpers/comments_helper.rb +2 -0
  34. data/spec/dummy_app/app/models/comment.rb +7 -0
  35. data/spec/dummy_app/app/views/comments/_comment.html.erb +9 -0
  36. data/spec/dummy_app/app/views/comments/_form.html.erb +40 -0
  37. data/spec/dummy_app/app/views/comments/_new_comment_links.html.erb +5 -0
  38. data/spec/dummy_app/app/views/comments/create.html.erb +7 -0
  39. data/spec/dummy_app/app/views/comments/create.js.erb +20 -0
  40. data/spec/dummy_app/app/views/comments/destroy.js.erb +1 -0
  41. data/spec/dummy_app/app/views/comments/edit.html.erb +6 -0
  42. data/spec/dummy_app/app/views/comments/escape_test.html.erb +1 -0
  43. data/spec/dummy_app/app/views/comments/index.html.erb +19 -0
  44. data/spec/dummy_app/app/views/comments/new.html.erb +7 -0
  45. data/spec/dummy_app/app/views/comments/show.html.erb +15 -0
  46. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  47. data/spec/dummy_app/app/views/prepended/show.html.erb +1 -0
  48. data/spec/dummy_app/bin/bundle +3 -0
  49. data/spec/dummy_app/bin/rails +4 -0
  50. data/spec/dummy_app/bin/rake +4 -0
  51. data/spec/dummy_app/bin/setup +34 -0
  52. data/spec/dummy_app/bin/update +29 -0
  53. data/spec/dummy_app/config/application.rb +18 -0
  54. data/spec/dummy_app/config/boot.rb +3 -0
  55. data/spec/dummy_app/config/database.yml +7 -0
  56. data/spec/dummy_app/config/environment.rb +5 -0
  57. data/spec/dummy_app/config/environments/development.rb +54 -0
  58. data/spec/dummy_app/config/environments/test.rb +53 -0
  59. data/spec/dummy_app/config/initializers/secret_token.rb +3 -0
  60. data/spec/dummy_app/config/routes.rb +7 -0
  61. data/spec/dummy_app/config/secrets.yml +5 -0
  62. data/spec/dummy_app/config.ru +4 -0
  63. data/spec/dummy_app/db/migrate/20110209210252_create_comments.rb +14 -0
  64. data/spec/dummy_app/db/migrate/20110209210315_add_attachment_to_comment.rb +15 -0
  65. data/spec/dummy_app/db/migrate/20110714205346_add_other_attachment_to_comment.rb +8 -0
  66. data/spec/dummy_app/db/schema.rb +31 -0
  67. data/spec/dummy_app/db/seeds.rb +7 -0
  68. data/spec/features/comments_spec.rb +414 -0
  69. data/spec/features/prepended_spec.rb +9 -0
  70. data/spec/fixtures/hi.txt +1 -0
  71. data/spec/fixtures/qr.jpg +0 -0
  72. data/spec/spec_helper.rb +40 -0
  73. data/spec/support/arel_helper.rb +15 -0
  74. data/spec/support/connection_helper.rb +12 -0
  75. data/spec/support/integration_helper.rb +28 -0
  76. data/vendor/assets/javascripts/jquery.iframe-transport.js +41 -27
  77. data/vendor/assets/javascripts/jquery.remotipart.js +3 -1
  78. metadata +157 -27
  79. data/Gemfile.lock +0 -20
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6613ef182593408aa806dbc14790a9f5c31717d7096657f9238efec23e102977
4
+ data.tar.gz: 9f96a7481ff473943ae7b1e5ec745a8b179b8ae8f615809b3790f7683b687f1e
5
+ SHA512:
6
+ metadata.gz: 58567b707f27b4eb40eb5020e8fed6763fbb1d895efacb9ddc4c1252b1073c5373180d668de6f9a2b306a922f807a06617458c9ac78eb3dff1723ee0481df1fb
7
+ data.tar.gz: e19c0a28fecdfa2a8bdfb5bc0024263a1fc4de5dadb3a9a425af75367de672c0ec0339bcced53c33bceb11100fdb382fee465a86a45e8215405d4cf741d213c8
data/.travis.yml ADDED
@@ -0,0 +1,35 @@
1
+ language: ruby
2
+
3
+ before_install:
4
+ # https://github.com/danmayer/coverband/issues/162#issuecomment-452173268
5
+ - rm /home/travis/.rvm/gems/*/specifications/bundler-2.*.gemspec || true
6
+ - gem install bundler -v '<2'
7
+
8
+ bundler_args: --without development --jobs=3 --retry=3 --path=../vendor/bundle
9
+
10
+ cache: bundler
11
+
12
+ env:
13
+ matrix:
14
+ - JQUERY_VERSION=
15
+
16
+ rvm:
17
+ - 2.5.5
18
+
19
+ gemfile:
20
+ - gemfiles/rails_3.2.gemfile
21
+ - gemfiles/rails_4.2.gemfile
22
+ - gemfiles/rails_5.2.gemfile
23
+ - gemfiles/rails_6.0.gemfile
24
+
25
+ dist: trusty
26
+
27
+ sudo: false
28
+
29
+ matrix:
30
+ include:
31
+ - env: JQUERY_VERSION=2
32
+ gemfile: gemfiles/rails_6.0.gemfile
33
+ - env: JQUERY_VERSION=3
34
+ gemfile: gemfiles/rails_6.0.gemfile
35
+ fast_finish: true
data/Appraisals ADDED
@@ -0,0 +1,25 @@
1
+ appraise "rails-3.2" do
2
+ gem 'rails', '~> 3.2.0'
3
+ gem 'test-unit', '~> 3.0'
4
+ gem "strong_parameters"
5
+
6
+ group :development, :test do
7
+ gem 'sqlite3', '~> 1.3.5'
8
+ end
9
+ end
10
+
11
+ appraise "rails-4.2" do
12
+ gem 'rails', '~> 4.2.0'
13
+
14
+ group :development, :test do
15
+ gem 'sqlite3', '~> 1.3.6'
16
+ end
17
+ end
18
+
19
+ appraise "rails-5.2" do
20
+ gem 'rails', '~> 5.2.0'
21
+ end
22
+
23
+ appraise "rails-6.0" do
24
+ gem 'rails', '~> 6.0.0.rc1'
25
+ end
data/Gemfile CHANGED
@@ -2,9 +2,22 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
4
  gem 'rake'
5
- gem 'jeweler'
5
+ gem 'jeweler', github: 'technicalpickles/jeweler'
6
6
  # This conflicts with jeweler gemspec generation,
7
7
  # causes dependencies to be added to gemspec recursively
8
8
  #gemspec
9
9
  end
10
10
 
11
+ group :development, :test do
12
+ gem 'appraisal'
13
+ gem 'jquery-rails'
14
+ gem 'sqlite3'
15
+ gem 'paperclip'
16
+ gem 'remotipart', path: '.'
17
+ end
18
+
19
+ group :test do
20
+ gem 'database_cleaner'
21
+ gem 'poltergeist'
22
+ gem 'rspec-rails'
23
+ end
data/History.rdoc CHANGED
@@ -1,5 +1,39 @@
1
1
  = History
2
2
 
3
+ === 1.4.4 / 2019-12-29
4
+
5
+ * Fixed Rails 6 autoloading deprecation.
6
+ * Fixed ActiveScaffold incompatibility.
7
+
8
+ === 1.4.3 / 2019-05-23
9
+
10
+ * Fixed xhr.responseText not being populated.
11
+ * Security: fixed cross-site scripting vulnerability when server renders user input.
12
+
13
+ === 1.4.2 / 2018-04-25
14
+
15
+ * Fixed ActionView::Template::Error in web-console.
16
+
17
+ === 1.4.0 / 2018-04-09
18
+
19
+ * Added jQuery 3 compatibility.
20
+ * Changed to use ActiveSupport lazy load hooks on initialization.
21
+ * Changed jQuery iframe-transport to v1.0.1.
22
+ * Fixed to preserve original return value of render call for non-remotipart requests.
23
+ * Fixed remote javascript with &quot; not being executed.
24
+ * Fixed method signature of render_with_remotipart, making RJS templates not usable.
25
+
26
+ === 1.3.1 / 2016-10-06
27
+
28
+ * Fixed remote form submit not working with Firefox 49.
29
+
30
+ === 1.3.0 / 2016-09-14
31
+
32
+ * Added Rails 5 support.
33
+ * Added an event `ajax:remotipartComplete`, which will be fired when the ajax upload completes.
34
+ * Changed to preserve original input files upon submit.
35
+ * Fixed TypeError when POST body is empty with Rails 3.
36
+
3
37
  === 1.2.1 / 2013-07-07
4
38
 
5
39
  * Added automatic authenticity_token detection and appending to iframe submission.
data/LICENSE CHANGED
@@ -1,3 +1,7 @@
1
+ ============================================
2
+ Remotipart is licensed under the MIT License
3
+ ============================================
4
+
1
5
  Copyright (c) 2009 Greg Leppert
2
6
 
3
7
  Permission is hereby granted, free of charge, to any person obtaining
data/README.rdoc CHANGED
@@ -1,4 +1,8 @@
1
- = Remotipart: Rails jQuery File Upload
1
+ = Remotipart: Rails jQuery File Uploads
2
+
3
+ {<img src="https://badge.fury.io/rb/remotipart.svg" alt="Gem Version" />}[https://badge.fury.io/rb/remotipart]
4
+ {<img src="https://travis-ci.com/JangoSteve/remotipart.svg?branch=master" alt="Build Status" />}[https://travis-ci.com/JangoSteve/remotipart]
5
+ {<img src="https://codeclimate.com/github/JangoSteve/remotipart/badges/gpa.svg" />}[https://codeclimate.com/github/JangoSteve/remotipart]
2
6
 
3
7
  Remotipart is a Ruby on Rails gem enabling AJAX file uploads with jQuery in Rails 3 and Rails 4 remote forms.
4
8
  This gem augments the native Rails jQuery remote form functionality enabling asynchronous file uploads with little to no modification to your application.
@@ -9,7 +13,9 @@ This gem augments the native Rails jQuery remote form functionality enabling asy
9
13
  == Dependencies
10
14
 
11
15
  * {Rails 3 or Rails 4}[http://github.com/rails/rails]
12
- * {The jquery-rails gem}[http://rubygems.org/gems/jquery-rails] (included in Rails 3 and Rails 4 by default), which installs {jQuery}[http://jquery.com] and the {Rails jQuery driver (jquery-ujs)}[https://github.com/rails/jquery-ujs]
16
+ * {The jquery-rails gem}[http://rubygems.org/gems/jquery-rails]
17
+
18
+ <em>The jquery-rails gem is included in Rails 3 and Rails 4 by default, and installs {jQuery}[http://jquery.com] and the {Rails jQuery UJS driver (jquery-ujs)}[https://github.com/rails/jquery-ujs]</em>
13
19
 
14
20
  == Installation
15
21
 
@@ -29,7 +35,7 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
29
35
 
30
36
  bundle install
31
37
 
32
- === Rails 3.1
38
+ === Rails 3.1 and Rails 4
33
39
 
34
40
  [2.]
35
41
  The necessary js files will automatically be added to the asset pipeline, so add the following to app/assets/javascripts/application.js (right after <tt>//= require jquery_ujs</tt>):
@@ -53,7 +59,7 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
53
59
  * For multipart / forms with file inputs, set your form_for to remote as you would for a normal ajax form:
54
60
  :remote => true
55
61
  * When Javascript is enabled in the user's browser, the form, including the file, will be submitted asynchronously to your controller with:
56
- :format == 'js'
62
+ :format => 'js'
57
63
  * If you need to determine if a particular request was made via a remotipart-enabled form...
58
64
  * from your Rails controller or view:
59
65
 
@@ -63,10 +69,16 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
63
69
  $(form).bind("ajax:success", function(){
64
70
  if ( $(this).data('remotipartSubmitted') )
65
71
  });
72
+ * If you want to be notified when the upload is complete (which can be either success or error)
73
+ * from your javascript:
66
74
 
75
+ $(form).on("ajax:remotipartComplete", function(e, data){
76
+ console.log(e, data)
77
+ });
78
+
67
79
  === Example
68
80
 
69
- sample_layout.html.erb
81
+ <tt>sample_layout.html.erb</tt>
70
82
  <%= form_for @sample, :html => { :multipart => true }, :remote => true do |f| %>
71
83
  <div class="field">
72
84
  <%= f.label :file %>
@@ -77,7 +89,7 @@ sample_layout.html.erb
77
89
  </div>
78
90
  <% end %>
79
91
 
80
- sample_controller.rb
92
+ <tt>sample_controller.rb</tt>
81
93
  def create
82
94
  respond_to do |format|
83
95
  if @sample.save
@@ -86,7 +98,7 @@ sample_controller.rb
86
98
  end
87
99
  end
88
100
 
89
- create.js.erb
101
+ <tt>create.js.erb</tt>
90
102
  // Display a Javascript alert
91
103
  alert('success!');
92
104
  <% if remotipart_submitted? %>
@@ -95,6 +107,21 @@ create.js.erb
95
107
  alert('submitted via native jquery-ujs')
96
108
  <% end %>
97
109
 
110
+ The content type requested from the application can be overridden via the <tt>data-type</tt> HTML5 attribute:
111
+
112
+ <tt>sample_layout2.html.erb</tt>
113
+ <%= form_for @sample, :html => { :multipart => true }, :remote => true, :data => { :type => :html } do |f| %>
114
+ <div class="field">
115
+ <%= f.label :file %>
116
+ <%= f.file_field :file %>
117
+ </div>
118
+ <div class="actions">
119
+ <%= f.submit %>
120
+ </div>
121
+ <% end %>
122
+
123
+ In this case, the application should serve HTML using a <tt>create.html.erb</tt> template instead of JavaScript.
124
+
98
125
  == Note on Patches/Pull Requests
99
126
 
100
127
  <b>If you have a general improvement, optimization, or refactoring, please {read this first}[https://github.com/formasfunction/remotipart/wiki/Refactoring-and-Improving-Remotipart].</b>
@@ -114,7 +141,7 @@ to test the file upload functionality of remotipart (since the browsers running
114
141
  upload input using javascript). So, instead we created a demo Rails app using remotipart with all remotipart functionality tested using RSpec and Capybara.
115
142
 
116
143
  * {Demo Rails App with Tests}[https://github.com/JangoSteve/Rails-jQuery-Demo/tree/remotipart]
117
- * {Tests}[https://github.com/JangoSteve/Rails-jQuery-Demo/blob/remotipart/spec/integration/comments_spec.rb]
144
+ * {Tests}[https://github.com/JangoSteve/Rails-jQuery-Demo/blob/master/spec/features/comments_spec.rb]
118
145
 
119
146
  To run tests:
120
147
 
data/Rakefile CHANGED
@@ -21,13 +21,6 @@ rescue LoadError
21
21
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
22
  end
23
23
 
24
- require 'rake/testtask'
25
- Rake::TestTask.new(:test) do |test|
26
- test.libs << 'lib' << 'test'
27
- test.pattern = 'test/**/test_*.rb'
28
- test.verbose = true
29
- end
30
-
31
24
  begin
32
25
  require 'rcov/rcovtask'
33
26
  Rcov::RcovTask.new do |test|
@@ -51,3 +44,8 @@ Rake::RDocTask.new do |rdoc|
51
44
  rdoc.rdoc_files.include('README*')
52
45
  rdoc.rdoc_files.include('lib/**/*.rb')
53
46
  end
47
+
48
+ require 'rspec/core/rake_task'
49
+ RSpec::Core::RakeTask.new(:spec)
50
+
51
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.0"
6
+ gem "test-unit", "~> 3.0"
7
+ gem "strong_parameters"
8
+
9
+ group :development do
10
+ gem "rake"
11
+ gem "jeweler"
12
+ end
13
+
14
+ group :development, :test do
15
+ gem "appraisal"
16
+ gem "jquery-rails"
17
+ gem "sqlite3", "~> 1.3.5"
18
+ gem "paperclip"
19
+ gem "remotipart", path: "../"
20
+ end
21
+
22
+ group :test do
23
+ gem "database_cleaner"
24
+ gem "poltergeist"
25
+ gem "rspec-rails"
26
+ end
@@ -0,0 +1,24 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+
7
+ group :development do
8
+ gem "rake"
9
+ gem "jeweler"
10
+ end
11
+
12
+ group :development, :test do
13
+ gem "appraisal"
14
+ gem "jquery-rails"
15
+ gem "sqlite3", "~> 1.3.6"
16
+ gem "paperclip"
17
+ gem "remotipart", path: "../"
18
+ end
19
+
20
+ group :test do
21
+ gem "database_cleaner"
22
+ gem "poltergeist"
23
+ gem "rspec-rails"
24
+ end
@@ -0,0 +1,24 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+
7
+ group :development do
8
+ gem "rake"
9
+ gem "jeweler"
10
+ end
11
+
12
+ group :development, :test do
13
+ gem "appraisal"
14
+ gem "jquery-rails"
15
+ gem "sqlite3"
16
+ gem "paperclip"
17
+ gem "remotipart", path: "../"
18
+ end
19
+
20
+ group :test do
21
+ gem "database_cleaner"
22
+ gem "poltergeist"
23
+ gem "rspec-rails"
24
+ end
@@ -0,0 +1,24 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.0.rc1"
6
+
7
+ group :development do
8
+ gem "rake"
9
+ gem "jeweler"
10
+ end
11
+
12
+ group :development, :test do
13
+ gem "appraisal"
14
+ gem "jquery-rails"
15
+ gem "sqlite3"
16
+ gem "paperclip"
17
+ gem "remotipart", path: "../"
18
+ end
19
+
20
+ group :test do
21
+ gem "database_cleaner"
22
+ gem "poltergeist"
23
+ gem "rspec-rails"
24
+ end
@@ -1,6 +1,6 @@
1
1
  module Remotipart
2
2
 
3
- # A middleware to look for our form parameters and
3
+ # A middleware to look for our form parameters and
4
4
  # encourage Rails to respond with the requested format
5
5
  class Middleware
6
6
  def initialize app
@@ -9,7 +9,12 @@ module Remotipart
9
9
 
10
10
  def call env
11
11
  # Get request params
12
- params = Rack::Request.new(env).params
12
+ begin
13
+ params = Rack::Request.new(env).params
14
+ rescue TypeError => e
15
+ ::Rails.logger.warn e.message
16
+ ::Rails.logger.warn e.backtrace.join("\n")
17
+ end
13
18
 
14
19
  if params
15
20
  # This was using an iframe transport, and is therefore an XHR
@@ -19,8 +24,8 @@ module Remotipart
19
24
  end
20
25
 
21
26
  # Override the accepted format, because it isn't what we really want
22
- if params['X-Http-Accept']
23
- env['HTTP_ACCEPT'] = params['X-Http-Accept']
27
+ if params['X-HTTP-Accept']
28
+ env['HTTP_ACCEPT'] = params['X-HTTP-Accept']
24
29
  end
25
30
  end
26
31
 
@@ -4,17 +4,27 @@ module Remotipart
4
4
 
5
5
  class Engine < ::Rails::Engine
6
6
  initializer "remotipart.view_helper" do
7
- ActionView::Base.send :include, RequestHelper
8
- ActionView::Base.send :include, ViewHelper
7
+ ActiveSupport.on_load :action_view do
8
+ include RequestHelper
9
+ include ViewHelper
10
+ end
9
11
  end
10
12
 
11
13
  initializer "remotipart.controller_helper" do
12
- ActionController::Base.send :include, RequestHelper
13
- ActionController::Base.send :include, RenderOverrides
14
+ ActiveSupport.on_load :action_controller do
15
+ include RequestHelper
16
+ include RenderOverrides
17
+ end
14
18
  end
15
19
 
16
20
  initializer "remotipart.include_middelware" do
17
- config.app_middleware.insert_after ActionDispatch::ParamsParser, Middleware
21
+ if ::Rails.version >= '5'
22
+ # Rails 5 no longer instantiates ActionDispatch::ParamsParser
23
+ # https://github.com/rails/rails/commit/a1ced8b52ce60d0634e65aa36cb89f015f9f543d
24
+ config.app_middleware.use Middleware
25
+ else
26
+ config.app_middleware.insert_after ActionDispatch::ParamsParser, Middleware
27
+ end
18
28
  end
19
29
  end
20
30
 
@@ -23,13 +23,17 @@ module Remotipart
23
23
  end
24
24
 
25
25
  initializer "remotipart.view_helper" do
26
- ActionView::Base.send :include, RequestHelper
27
- ActionView::Base.send :include, ViewHelper
26
+ ActiveSupport.on_load(:action_view) do
27
+ include RequestHelper
28
+ include ViewHelper
29
+ end
28
30
  end
29
31
 
30
32
  initializer "remotipart.controller_helper" do
31
- ActionController::Base.send :include, RequestHelper
32
- ActionController::Base.send :include, RenderOverrides
33
+ ActiveSupport.on_load(:action_controller) do
34
+ include RequestHelper
35
+ include RenderOverrides
36
+ end
33
37
  end
34
38
 
35
39
  initializer "remotipart.include_middelware" do
@@ -1,6 +1,6 @@
1
1
  module Remotipart
2
2
  module Rails
3
- VERSION = "1.2.1"
4
- IFRAMETRANSPORT_VERSION = "02.06.2013"
3
+ VERSION = "1.4.4"
4
+ IFRAMETRANSPORT_VERSION = "1.0.1.remotipart"
5
5
  end
6
6
  end
@@ -3,21 +3,43 @@ module Remotipart
3
3
  # as expected by iframe-transport.
4
4
  module RenderOverrides
5
5
  include ERB::Util
6
+ include ActionView::Helpers::JavaScriptHelper
6
7
 
7
8
  def self.included(base)
8
9
  base.class_eval do
9
- alias_method_chain :render, :remotipart
10
+ if respond_to? :prepend
11
+ base.prepend Prependable
12
+ else
13
+ base.include Includable
14
+ # Do not use alias_method_chain for compatibility
15
+ alias render_without_remotipart render
16
+ alias render render_with_remotipart
17
+ end
10
18
  end
11
19
  end
12
20
 
13
- def render_with_remotipart *args
14
- render_without_remotipart *args
21
+ module Prependable
22
+ def render(*args, &block)
23
+ treat_render_for_remotipart super(*args, &block)
24
+ end
25
+ end
26
+
27
+ module Includable
28
+ def render_with_remotipart(*args, &block)
29
+ treat_render_for_remotipart render_without_remotipart(*args, &block)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def treat_render_for_remotipart(render_return_value)
15
36
  if remotipart_submitted?
16
- textarea_body = response.content_type == 'text/html' ? html_escape(response.body) : response.body
17
- response.body = %{<textarea data-type=\"#{response.content_type}\" data-status=\"#{response.response_code}\" data-statusText=\"#{response.message}\">#{textarea_body}</textarea>}
18
- response.content_type = Mime::HTML
37
+ response.body = %{<script type="text/javascript">try{window.parent.document;}catch(err){document.domain=document.domain;}</script><textarea data-type="#{response.content_type}" data-status="#{response.response_code}" data-statusText="#{response.message}"></textarea><script type="text/javascript">document.querySelector("textarea").value="#{escape_javascript(response.body)}";</script>}
38
+ response.content_type = ::Rails.version >= '5' ? Mime[:html] : Mime::HTML
39
+ response_body
40
+ else
41
+ render_return_value
19
42
  end
20
- response_body
21
43
  end
22
44
  end
23
45
  end
@@ -2,6 +2,8 @@ module Remotipart
2
2
  module RequestHelper
3
3
  def remotipart_submitted?
4
4
  params[:remotipart_submitted] ? true : false
5
+ rescue
6
+ false
5
7
  end
6
8
 
7
9
  alias :remotipart_requested? :remotipart_submitted?
@@ -1,9 +1,11 @@
1
1
  module Remotipart
2
2
  module ViewHelper
3
+
3
4
  #No longer used
4
5
  #Retrained to prevent issues while updating
5
6
  def remotipart_response(options = {}, &block)
6
7
  with_output_buffer(&block)
7
8
  end
9
+
8
10
  end
9
11
  end