Permalink
Browse files

Working on getting the generator up and running

  • Loading branch information...
1 parent 6813123 commit be0afb4c82ca00b2780adbb3a50a4bcd975195ca @leppert leppert committed Apr 9, 2010
Showing with 129 additions and 0 deletions.
  1. +1 −0 Rakefile
  2. +14 −0 lib/generators/remotipart_generator.rb
  3. +47 −0 lib/generators/templates/jquery.remotipart.js
  4. +11 −0 lib/remotipart.rb
  5. +56 −0 remotipart.gemspec
View
@@ -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
@@ -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
@@ -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();
+ }
+ }
+ });
+
+});
View
@@ -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
View
@@ -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.