tfe-remotipart 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -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.
@@ -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.4.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.
@@ -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 = "tfe-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", "todd@toddeichel.com"]
14
+ gem.homepage = "http://github.com/formasfunction/remotipart"
15
+ gem.authors = ["Greg Leppert", "todd@toddeichel.com"]
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.2.1
@@ -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,50 @@
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
+
15
+ url = url.split('?'); // split on GET params
16
+ if(url[0].substr(-3) != '.js') url[0] += '.js'; // force rails to respond to respond to the request with :format = js
17
+ url = url.join('?'); // join on GET params
18
+
19
+ el.ajaxSubmit({
20
+ url: url,
21
+ dataType: 'script',
22
+ beforeSend: function (xhr) {
23
+ el.trigger('ajax:loading', xhr);
24
+ },
25
+ success: function (data, status, xhr) {
26
+ el.trigger('ajax:success', [data, status, xhr]);
27
+ },
28
+ complete: function (xhr) {
29
+ el.trigger('ajax:complete', xhr);
30
+ },
31
+ error: function (xhr, status, error) {
32
+ el.trigger('ajax:failure', [xhr, status, error]);
33
+ }
34
+ });
35
+ }
36
+
37
+ el.trigger('ajax:after');
38
+ }
39
+ },
40
+ _callRemote: $.fn.callRemote, //store the original rails callRemote
41
+ callRemote: function(){ //override the rails callRemote and check for a file input
42
+ if(this.find('input:file').length){
43
+ this.callRemotipart();
44
+ } else {
45
+ this._callRemote();
46
+ }
47
+ }
48
+ });
49
+
50
+ });
@@ -0,0 +1,11 @@
1
+ module Remotipart
2
+ def remotipart_response(options = {}, &block)
3
+ response.content_type = Mime::HTML
4
+ content = with_output_buffer(&block)
5
+ text_area_tag('remotipart_response', String.new(content), options)
6
+ end
7
+ end
8
+
9
+ class ActionView::Base
10
+ include Remotipart
11
+ end
@@ -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
@@ -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{tfe-remotipart}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Greg Leppert", "todd@toddeichel.com"]
12
+ s.date = %q{2011-01-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 = ["greg@formasfunction.com", "todd@toddeichel.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
+ "test/helper.rb",
33
+ "test/test_remotipart.rb",
34
+ "tfe-remotipart.gemspec"
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.7}
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::VERSION) >= 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
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tfe-remotipart
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
11
+ platform: ruby
12
+ authors:
13
+ - Greg Leppert
14
+ - todd@toddeichel.com
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-09 00:00:00 -05:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: thoughtbot-shoulda
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ 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 "
37
+ email:
38
+ - greg@formasfunction.com
39
+ - todd@toddeichel.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - LICENSE
46
+ - README.rdoc
47
+ files:
48
+ - .document
49
+ - .gitignore
50
+ - LICENSE
51
+ - README.rdoc
52
+ - Rakefile
53
+ - VERSION
54
+ - lib/generators/remotipart_generator.rb
55
+ - lib/generators/templates/jquery.remotipart.js
56
+ - lib/remotipart.rb
57
+ - test/helper.rb
58
+ - test/test_remotipart.rb
59
+ - tfe-remotipart.gemspec
60
+ has_rdoc: true
61
+ homepage: http://github.com/formasfunction/remotipart
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.
94
+ test_files:
95
+ - test/helper.rb
96
+ - test/test_remotipart.rb