forked from leppert/remotipart
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on getting the generator up and running
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
require 'rails/generators' | |||
|
|||
class RemotipartGenerator < Rails::Generators::Base | |||
def self.source_root | |||
File.join(File.dirname(__FILE__), 'templates') | |||
end | |||
|
|||
def install_remotipart | |||
copy_file( | |||
'jquery.remotipart.js', | |||
'public/javascripts/jquery.remotipart.js' | |||
) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,47 @@ | |||
jQuery(function ($) { | |||
$.fn.extend({ | |||
/** | |||
* Handles execution of remote calls involving file uploads, firing overridable events along the way | |||
*/ | |||
callRemotipart: function () { | |||
var el = this, | |||
url = el.attr('action'); | |||
|
|||
if (url === undefined) { | |||
throw "No URL specified for remote call (action must be present)."; | |||
} else { | |||
if (el.triggerAndReturn('ajax:before')) { | |||
if(url.substr(-3) != '.js') url += '.js'; //force rails to respond to respond to the request with :format = js | |||
el.ajaxSubmit({ | |||
url: url, | |||
dataType: 'script', | |||
beforeSend: function (xhr) { | |||
el.trigger('ajax:loading', xhr); | |||
}, | |||
success: function (data, status, xhr) { | |||
console.log(data); | |||
el.trigger('ajax:success', [data, status, xhr]); | |||
}, | |||
complete: function (xhr) { | |||
el.trigger('ajax:complete', xhr); | |||
}, | |||
error: function (xhr, status, error) { | |||
el.trigger('ajax:failure', [xhr, status, error]); | |||
} | |||
}); | |||
} | |||
|
|||
el.trigger('ajax:after'); | |||
} | |||
}, | |||
_callRemote: $.fn.callRemote, //store the original rails callRemote | |||
callRemote: function(){ //override the rails callRemote and check for a file input | |||
if(this.find('input:file').length){ | |||
this.callRemotipart(); | |||
} else { | |||
this._callRemote(); | |||
} | |||
} | |||
}); | |||
|
|||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
module Remotipart | |||
def remotipart_return(&block) | |||
response.content_type = Mime::HTML | |||
content = with_output_buffer(&block) | |||
text_area_tag 'remotipart_return', content | |||
end | |||
end | |||
|
|||
class ActionView::Base | |||
include Remotipart | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
# Generated by jeweler | |||
# DO NOT EDIT THIS FILE DIRECTLY | |||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | |||
# -*- encoding: utf-8 -*- | |||
|
|||
Gem::Specification.new do |s| | |||
s.name = %q{remotipart} | |||
s.version = "0.0.0" | |||
|
|||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | |||
s.authors = ["Greg Leppert"] | |||
s.date = %q{2010-04-08} | |||
s.description = %q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery. | |||
This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application. | |||
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/). | |||
} | |||
s.email = %q{greg@formasfunction.com} | |||
s.extra_rdoc_files = [ | |||
"LICENSE", | |||
"README.rdoc" | |||
] | |||
s.files = [ | |||
".document", | |||
".gitignore", | |||
"LICENSE", | |||
"README.rdoc", | |||
"Rakefile", | |||
"VERSION", | |||
"lib/remotipart.rb", | |||
"test/helper.rb", | |||
"test/test_remotipart.rb" | |||
] | |||
s.homepage = %q{http://github.com/formasfunction/remotipart} | |||
s.rdoc_options = ["--charset=UTF-8"] | |||
s.require_paths = ["lib"] | |||
s.rubygems_version = %q{1.3.6} | |||
s.summary = %q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.} | |||
s.test_files = [ | |||
"test/helper.rb", | |||
"test/test_remotipart.rb" | |||
] | |||
|
|||
if s.respond_to? :specification_version then | |||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | |||
s.specification_version = 3 | |||
|
|||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then | |||
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"]) | |||
else | |||
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"]) | |||
end | |||
else | |||
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"]) | |||
end | |||
end | |||
|