remotipart 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9e9bc4a555dcec65d5919d97b7f56952ef8b8aa
4
+ data.tar.gz: e84ba4304c5491427d6eff3d29aa86cb98ecf3f5
5
+ SHA512:
6
+ metadata.gz: 441d87a73a0eee7e4304fd7dabebaf86ca189eb2ac9c274ee7ad0f69828963851c86c63387d869240255f74be6b582d3c46f0555f2aa08f45aab2a8c58eefb3e
7
+ data.tar.gz: 29deeb18c6fb76f3ef0a31f5e777a3d4ddd34124c01ad0b11cb53fea34655d238ceeb8e49c69369823318c4273d8cfd3dc36b82794cbc83382a09aa54f374609
@@ -1,5 +1,12 @@
1
1
  = History
2
2
 
3
+ === 1.3.0 / 2016-09-14
4
+
5
+ * Added Rails 5 support.
6
+ * Added an event `ajax:remotipartComplete`, which will be fired when the ajax upload completes.
7
+ * Changed to preserve original input files upon submit.
8
+ * Fixed TypeError when POST body is empty with Rails 3.
9
+
3
10
  === 1.2.1 / 2013-07-07
4
11
 
5
12
  * 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
@@ -1,4 +1,6 @@
1
- = Remotipart: Rails jQuery File Upload
1
+ = Remotipart: Rails jQuery File Uploads
2
+
3
+ {<img src="https://codeclimate.com/github/JangoSteve/remotipart/badges/gpa.svg" />}[https://codeclimate.com/github/JangoSteve/remotipart]
2
4
 
3
5
  Remotipart is a Ruby on Rails gem enabling AJAX file uploads with jQuery in Rails 3 and Rails 4 remote forms.
4
6
  This gem augments the native Rails jQuery remote form functionality enabling asynchronous file uploads with little to no modification to your application.
@@ -9,7 +11,9 @@ This gem augments the native Rails jQuery remote form functionality enabling asy
9
11
  == Dependencies
10
12
 
11
13
  * {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]
14
+ * {The jquery-rails gem}[http://rubygems.org/gems/jquery-rails]
15
+
16
+ <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
17
 
14
18
  == Installation
15
19
 
@@ -29,7 +33,7 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
29
33
 
30
34
  bundle install
31
35
 
32
- === Rails 3.1
36
+ === Rails 3.1 and Rails 4
33
37
 
34
38
  [2.]
35
39
  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 +57,7 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
53
57
  * For multipart / forms with file inputs, set your form_for to remote as you would for a normal ajax form:
54
58
  :remote => true
55
59
  * 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'
60
+ :format => 'js'
57
61
  * If you need to determine if a particular request was made via a remotipart-enabled form...
58
62
  * from your Rails controller or view:
59
63
 
@@ -63,10 +67,16 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
63
67
  $(form).bind("ajax:success", function(){
64
68
  if ( $(this).data('remotipartSubmitted') )
65
69
  });
70
+ * If you want to be notified when the upload is complete (which can be either success or error)
71
+ * from your javascript:
66
72
 
73
+ $(form).on("ajax:remotipartComplete", function(e, data){
74
+ console.log(e, data)
75
+ });
76
+
67
77
  === Example
68
78
 
69
- sample_layout.html.erb
79
+ <tt>sample_layout.html.erb</tt>
70
80
  <%= form_for @sample, :html => { :multipart => true }, :remote => true do |f| %>
71
81
  <div class="field">
72
82
  <%= f.label :file %>
@@ -77,7 +87,7 @@ sample_layout.html.erb
77
87
  </div>
78
88
  <% end %>
79
89
 
80
- sample_controller.rb
90
+ <tt>sample_controller.rb</tt>
81
91
  def create
82
92
  respond_to do |format|
83
93
  if @sample.save
@@ -86,7 +96,7 @@ sample_controller.rb
86
96
  end
87
97
  end
88
98
 
89
- create.js.erb
99
+ <tt>create.js.erb</tt>
90
100
  // Display a Javascript alert
91
101
  alert('success!');
92
102
  <% if remotipart_submitted? %>
@@ -95,6 +105,21 @@ create.js.erb
95
105
  alert('submitted via native jquery-ujs')
96
106
  <% end %>
97
107
 
108
+ The content type requested from the application can be overridden via the <tt>data-type</tt> HTML5 attribute:
109
+
110
+ <tt>sample_layout2.html.erb</tt>
111
+ <%= form_for @sample, :html => { :multipart => true }, :remote => true, :data => { :type => :html } do |f| %>
112
+ <div class="field">
113
+ <%= f.label :file %>
114
+ <%= f.file_field :file %>
115
+ </div>
116
+ <div class="actions">
117
+ <%= f.submit %>
118
+ </div>
119
+ <% end %>
120
+
121
+ In this case, the application should serve HTML using a <tt>create.html.erb</tt> template instead of JavaScript.
122
+
98
123
  == Note on Patches/Pull Requests
99
124
 
100
125
  <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 +139,7 @@ to test the file upload functionality of remotipart (since the browsers running
114
139
  upload input using javascript). So, instead we created a demo Rails app using remotipart with all remotipart functionality tested using RSpec and Capybara.
115
140
 
116
141
  * {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]
142
+ * {Tests}[https://github.com/JangoSteve/Rails-jQuery-Demo/blob/master/spec/features/comments_spec.rb]
118
143
 
119
144
  To run tests:
120
145
 
@@ -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
@@ -14,7 +14,13 @@ module Remotipart
14
14
  end
15
15
 
16
16
  initializer "remotipart.include_middelware" do
17
- config.app_middleware.insert_after ActionDispatch::ParamsParser, Middleware
17
+ if ::Rails.version >= '5'
18
+ # Rails 5 no longer instantiates ActionDispatch::ParamsParser
19
+ # https://github.com/rails/rails/commit/a1ced8b52ce60d0634e65aa36cb89f015f9f543d
20
+ config.app_middleware.use Middleware
21
+ else
22
+ config.app_middleware.insert_after ActionDispatch::ParamsParser, Middleware
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -1,6 +1,6 @@
1
1
  module Remotipart
2
2
  module Rails
3
- VERSION = "1.2.1"
3
+ VERSION = "1.3.0"
4
4
  IFRAMETRANSPORT_VERSION = "02.06.2013"
5
5
  end
6
6
  end
@@ -6,7 +6,9 @@ module Remotipart
6
6
 
7
7
  def self.included(base)
8
8
  base.class_eval do
9
- alias_method_chain :render, :remotipart
9
+ # Use neither alias_method_chain nor prepend for compatibility
10
+ alias render_without_remotipart render
11
+ alias render render_with_remotipart
10
12
  end
11
13
  end
12
14
 
@@ -14,8 +16,8 @@ module Remotipart
14
16
  render_without_remotipart *args
15
17
  if remotipart_submitted?
16
18
  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
19
+ 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_body}</textarea>}
20
+ response.content_type = ::Rails.version >= '5' ? Mime[:html] : Mime::HTML
19
21
  end
20
22
  response_body
21
23
  end
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: remotipart 1.3.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "remotipart"
8
- s.version = "1.2.1"
9
+ s.version = "1.3.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Greg Leppert", "Steve Schwartz"]
12
- s.date = "2013-07-08"
14
+ s.date = "2016-09-14"
13
15
  s.description = "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jquery-rails.\n This gem augments the native Rails 3 jQuery-UJS remote form function enabling asynchronous file uploads with little to no modification to your application.\n "
14
16
  s.email = ["greg@formasfunction.com", "steve@alfajango.com"]
15
17
  s.extra_rdoc_files = [
@@ -20,7 +22,6 @@ Gem::Specification.new do |s|
20
22
  ".document",
21
23
  "CONTRIBUTING.md",
22
24
  "Gemfile",
23
- "Gemfile.lock",
24
25
  "History.rdoc",
25
26
  "LICENSE",
26
27
  "README.rdoc",
@@ -41,12 +42,11 @@ Gem::Specification.new do |s|
41
42
  "vendor/assets/javascripts/jquery.remotipart.js"
42
43
  ]
43
44
  s.homepage = "http://opensource.alfajango.com/remotipart/"
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = "1.8.15"
45
+ s.rubygems_version = "2.5.1"
46
46
  s.summary = "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jquery-rails."
47
47
 
48
48
  if s.respond_to? :specification_version then
49
- s.specification_version = 3
49
+ s.specification_version = 4
50
50
 
51
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
52
  s.add_development_dependency(%q<rake>, [">= 0"])
@@ -115,7 +115,10 @@
115
115
  // and should revert all changes made to the page to enable the
116
116
  // submission via this transport.
117
117
  function cleanUp() {
118
- markers.prop('disabled', false);
118
+ markers.each(function(i){
119
+ $(this).replaceWith(files[i]);
120
+ markers.splice(i, 1);
121
+ });
119
122
  form.remove();
120
123
  iframe.bind("load", function() { iframe.remove(); });
121
124
  iframe.attr("src", "javascript:false;");
@@ -51,7 +51,9 @@
51
51
  // Allow remotipartSubmit to be cancelled if needed
52
52
  if ($.rails.fire(form, 'ajax:remotipartSubmit', [xhr, settings])) {
53
53
  // Second verse, same as the first
54
- $.rails.ajax(settings);
54
+ $.rails.ajax(settings).complete(function(data){
55
+ $.rails.fire(form, 'ajax:remotipartComplete', [data]);
56
+ });
55
57
  setTimeout(function(){ $.rails.disableFormElements(form); }, 20);
56
58
  }
57
59
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotipart
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
5
- prerelease:
4
+ version: 1.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Greg Leppert
@@ -10,34 +9,40 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-07-08 00:00:00.000000000Z
12
+ date: 2016-09-14 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- requirement: &70170920954340 !ruby/object:Gem::Requirement
18
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
- version_requirements: *70170920954340
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
26
28
  - !ruby/object:Gem::Dependency
27
29
  name: jeweler
28
- requirement: &70170920953080 !ruby/object:Gem::Requirement
29
- none: false
30
+ requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ! '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
- version_requirements: *70170920953080
37
- description: ! "Remotipart is a Ruby on Rails gem enabling remote multipart forms
38
- (AJAX style file uploads) with jquery-rails.\n This gem augments the native Rails
39
- 3 jQuery-UJS remote form function enabling asynchronous file uploads with little
40
- to no modification to your application.\n "
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX
43
+ style file uploads) with jquery-rails.\n This gem augments the native Rails 3
44
+ jQuery-UJS remote form function enabling asynchronous file uploads with little to
45
+ no modification to your application.\n "
41
46
  email:
42
47
  - greg@formasfunction.com
43
48
  - steve@alfajango.com
@@ -47,10 +52,9 @@ extra_rdoc_files:
47
52
  - LICENSE
48
53
  - README.rdoc
49
54
  files:
50
- - .document
55
+ - ".document"
51
56
  - CONTRIBUTING.md
52
57
  - Gemfile
53
- - Gemfile.lock
54
58
  - History.rdoc
55
59
  - LICENSE
56
60
  - README.rdoc
@@ -71,30 +75,26 @@ files:
71
75
  - vendor/assets/javascripts/jquery.remotipart.js
72
76
  homepage: http://opensource.alfajango.com/remotipart/
73
77
  licenses: []
78
+ metadata: {}
74
79
  post_install_message:
75
80
  rdoc_options: []
76
81
  require_paths:
77
82
  - lib
78
83
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
84
  requirements:
81
- - - ! '>='
85
+ - - ">="
82
86
  - !ruby/object:Gem::Version
83
87
  version: '0'
84
- segments:
85
- - 0
86
- hash: -3061483236240277448
87
88
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
89
  requirements:
90
- - - ! '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 1.8.15
95
+ rubygems_version: 2.5.1
96
96
  signing_key:
97
- specification_version: 3
97
+ specification_version: 4
98
98
  summary: Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style
99
99
  file uploads) with jquery-rails.
100
100
  test_files: []
@@ -1,20 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.8.4)
6
- bundler (~> 1.0)
7
- git (>= 1.2.5)
8
- rake
9
- rdoc
10
- json (1.7.6)
11
- rake (10.0.3)
12
- rdoc (3.12)
13
- json (~> 1.4)
14
-
15
- PLATFORMS
16
- ruby
17
-
18
- DEPENDENCIES
19
- jeweler
20
- rake