Skip to content

Commit

Permalink
Working on getting the generator up and running
Browse files Browse the repository at this point in the history
  • Loading branch information
leppert committed Apr 9, 2010
1 parent 6813123 commit be0afb4
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -14,6 +14,7 @@ begin
gem.homepage = "http://github.com/formasfunction/remotipart"
gem.authors = ["Greg Leppert"]
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
gem.add_dependency 'rails', '3.0.pre'
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
14 changes: 14 additions & 0 deletions lib/generators/remotipart_generator.rb
@@ -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
47 changes: 47 additions & 0 deletions lib/generators/templates/jquery.remotipart.js
@@ -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();
}
}
});

});
11 changes: 11 additions & 0 deletions lib/remotipart.rb
@@ -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
56 changes: 56 additions & 0 deletions remotipart.gemspec
@@ -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

0 comments on commit be0afb4

Please sign in to comment.