remotipart 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Greg Leppert
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,71 @@
1
+ = Remotipart
2
+
3
+ Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.
4
+ This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application.
5
+
6
+ == Dependencies
7
+
8
+ * {Rails 3}[http://github.com/rails/rails]
9
+ * {jQuery}[http://jquery.com]
10
+ * {The Rails jQuery driver}[http://github.com/rails/jquery-ujs]
11
+ * {The jQuery Form plugin}[http://jquery.malsup.com/form/]
12
+
13
+ == Installation
14
+
15
+ 1. Install the Remotipart gem
16
+ gem install remotipart
17
+ 2. Run the Remotipart generator to add jquery.remotipart.js to public/javascripts/
18
+ rails g remotipart
19
+ 3. Add the Javascript files for jQuery, the Rails jQuery driver, jQuery Form plugin, and Remotipart to your template, making sure to include jquery.remotipart.js *after* the jQuery and the Rails jQuery driver
20
+ <%= javascript_include_tag 'jquery-1.4.2.min', 'rails', 'jquery.form', 'jquery.remotipart' %>
21
+
22
+ == Usage
23
+
24
+ * For multipart / forms with file inputs, set your form_for to remote as you would for a normal ajax form:
25
+ :remote => true
26
+ * When Javascript is enabled in the user's browser, the form, including the file, will be submitted asynchronously to your controller with:
27
+ :format == 'js'
28
+ * In the JS response template for your controller action, wrap all of your response code in one remotipart_response block:
29
+ <%= remotipart_response do %> All Javascript response code goes here <% end %>
30
+
31
+ === Example
32
+
33
+ sample_layout.html.erb
34
+ <%= form_for @sample, :html => { :multipart => true }, :remote => true do |f| %>
35
+ <div class="field">
36
+ <%= f.label :file %>
37
+ <%= f.file_field :file %>
38
+ </div>
39
+ <div class="actions">
40
+ <%= f.submit %>
41
+ </div>
42
+ <% end %>
43
+
44
+ sample_controller.rb
45
+ def create
46
+ respond_to do |format|
47
+ if @sample.save
48
+ format.js
49
+ end
50
+ end
51
+ end
52
+
53
+ create.js.erb
54
+ <%= remotipart_response do %>
55
+ //Display a Javascript alert
56
+ alert('success!');
57
+ <% end %>
58
+
59
+ == Note on Patches/Pull Requests
60
+
61
+ * Fork the project.
62
+ * Make your feature addition or bug fix.
63
+ * Add tests for it. This is important so I don't break it in a
64
+ future version unintentionally.
65
+ * Commit, do not mess with rakefile, version, or history.
66
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
67
+ * Send me a pull request. Bonus points for topic branches.
68
+
69
+ == Copyright
70
+
71
+ Copyright (c) 2010 Greg Leppert. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "remotipart"
8
+ gem.summary = %Q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.}
9
+ gem.description = %Q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.
10
+ This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application.
11
+ It requires jQuery (http://jquery.com), the Rails jQuery driver (http://github.com/rails/jquery-ujs), and the jQuery Form plugin (http://jquery.malsup.com/form/).
12
+ }
13
+ gem.email = "greg@formasfunction.com"
14
+ gem.homepage = "http://github.com/formasfunction/remotipart"
15
+ gem.authors = ["Greg Leppert"]
16
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
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
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "remotipart #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,14 @@
1
+ require 'rails/generators'
2
+
3
+ class RemotipartGenerator < Rails::Generators::Base
4
+ def self.source_root
5
+ File.join(File.dirname(__FILE__), 'templates')
6
+ end
7
+
8
+ def install_remotipart
9
+ copy_file(
10
+ 'jquery.remotipart.js',
11
+ 'public/javascripts/jquery.remotipart.js'
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ jQuery(function ($) {
2
+ $.fn.extend({
3
+ /**
4
+ * Handles execution of remote calls involving file uploads, firing overridable events along the way
5
+ */
6
+ callRemotipart: function () {
7
+ var el = this,
8
+ url = el.attr('action');
9
+
10
+ if (url === undefined) {
11
+ throw "No URL specified for remote call (action must be present).";
12
+ } else {
13
+ if (el.triggerAndReturn('ajax:before')) {
14
+ if(url.substr(-3) != '.js') url += '.js'; //force rails to respond to respond to the request with :format = js
15
+ el.ajaxSubmit({
16
+ url: url,
17
+ dataType: 'script',
18
+ beforeSend: function (xhr) {
19
+ el.trigger('ajax:loading', xhr);
20
+ },
21
+ success: function (data, status, xhr) {
22
+ console.log(data);
23
+ el.trigger('ajax:success', [data, status, xhr]);
24
+ },
25
+ complete: function (xhr) {
26
+ el.trigger('ajax:complete', xhr);
27
+ },
28
+ error: function (xhr, status, error) {
29
+ el.trigger('ajax:failure', [xhr, status, error]);
30
+ }
31
+ });
32
+ }
33
+
34
+ el.trigger('ajax:after');
35
+ }
36
+ },
37
+ _callRemote: $.fn.callRemote, //store the original rails callRemote
38
+ callRemote: function(){ //override the rails callRemote and check for a file input
39
+ if(this.find('input:file').length){
40
+ this.callRemotipart();
41
+ } else {
42
+ this._callRemote();
43
+ }
44
+ }
45
+ });
46
+
47
+ });
data/lib/remotipart.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Remotipart
2
+ def remotipart_response(&block)
3
+ response.content_type = Mime::HTML
4
+ content = with_output_buffer(&block)
5
+ text_area_tag 'remotipart_response', content
6
+ end
7
+ end
8
+
9
+ class ActionView::Base
10
+ include Remotipart
11
+ end
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{remotipart}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Greg Leppert"]
12
+ s.date = %q{2010-04-09}
13
+ s.description = %q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.
14
+ This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application.
15
+ It requires jQuery (http://jquery.com), the Rails jQuery driver (http://github.com/rails/jquery-ujs), and the jQuery Form plugin (http://jquery.malsup.com/form/).
16
+ }
17
+ s.email = %q{greg@formasfunction.com}
18
+ s.extra_rdoc_files = [
19
+ "LICENSE",
20
+ "README.rdoc"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".gitignore",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/generators/remotipart_generator.rb",
30
+ "lib/generators/templates/jquery.remotipart.js",
31
+ "lib/remotipart.rb",
32
+ "remotipart.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_remotipart.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/formasfunction/remotipart}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_remotipart.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ end
58
+ end
59
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'remotipart'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRemotipart < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remotipart
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Greg Leppert
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-09 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.\n This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application.\n It requires jQuery (http://jquery.com), the Rails jQuery driver (http://github.com/rails/jquery-ujs), and the jQuery Form plugin (http://jquery.malsup.com/form/).\n "
33
+ email: greg@formasfunction.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - lib/generators/remotipart_generator.rb
49
+ - lib/generators/templates/jquery.remotipart.js
50
+ - lib/remotipart.rb
51
+ - remotipart.gemspec
52
+ - test/helper.rb
53
+ - test/test_remotipart.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/formasfunction/remotipart
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.6
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.
84
+ test_files:
85
+ - test/helper.rb
86
+ - test/test_remotipart.rb