diff --git a/README.md b/README.md index f4efa58b..fd8dee60 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ In your Gemfile, add this line: Then, run `bundle install`. To invoke the generator, run: - rails generate jquery:install #--ui to enable jQuery UI + rails generate jquery:install #--ui to enable jQuery UI --version to install specific version of JQuery (default is 1.4.2) You're done! Don't forget to output `csrf_meta_tag` somewhere inside your `` tag in your layout! diff --git a/jquery-rails.gemspec b/jquery-rails.gemspec index efd448ab..493a8173 100644 --- a/jquery-rails.gemspec +++ b/jquery-rails.gemspec @@ -11,11 +11,11 @@ Gem::Specification.new do |s| s.summary = "Use jQuery with Rails 3" s.description = "This gem provides a Rails generator to install jQuery and the jQuery-ujs driver into your Rails 3 application, and then have them included automatically instead of Prototype." - s.required_rubygems_version = ">= 1.3.6" + s.required_rubygems_version = "~> 1.3.6" s.rubyforge_project = "jquery-rails" - s.add_dependency "rails", "~>3.0.0.rc" - s.add_development_dependency "bundler", ">= 1.0.0.rc.6.pre" + s.add_dependency "rails", "~> 3.0" + s.add_development_dependency "bundler", "~> 1.0.0" s.files = `git ls-files`.split("\n") s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/} diff --git a/lib/generators/jquery/install/install_generator.rb b/lib/generators/jquery/install/install_generator.rb index 6206e299..ed6f2fd5 100644 --- a/lib/generators/jquery/install/install_generator.rb +++ b/lib/generators/jquery/install/install_generator.rb @@ -1,8 +1,11 @@ module Jquery module Generators class InstallGenerator < ::Rails::Generators::Base - desc "This generator downloads and installs jQuery 1.4.2, jQuery-ujs HEAD, and (optionally) jQuery UI 1.8.4" + desc "This generator downloads and installs jQuery, jQuery-ujs HEAD, and (optionally) jQuery UI 1.8.4" class_option :ui, :type => :boolean, :default => false, :desc => "Indicates when to Include JQueryUI (minified version; source: Google Libraries API)" + class_option :version, :type => :string, :default => "1.4.2", :desc => "Indicates which version of JQuery to fetch (source: Google Libraries API)" + @@versions = %w( 1.4.2 1.4.1 1.4.0 1.3.2 1.3.1 1.3.0 1.2.6 ) + def remove_prototype %w(controls.js dragdrop.js effects.js prototype.js).each do |js| @@ -12,8 +15,15 @@ def remove_prototype def download_jquery # Downloading latest jQuery - get "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "public/javascripts/jquery.min.js" - get "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js", "public/javascripts/jquery.js" + if @@versions.include?(options.version) + puts "Fetching the version #{options.version} of JQuery!" + get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.min.js", "public/javascripts/jquery.min.js" + get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.js", "public/javascripts/jquery.js" + else + puts "Version #{options.version} is not a valid version; fetching the #{@@versions[0]} (default) version of JQuery!" + get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[0]}/jquery.min.js", "public/javascripts/jquery.min.js" + get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[0]}/jquery.js", "public/javascripts/jquery.js" + end # Downloading latest jQueryUI minified get "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js", "public/javascripts/jquery-ui.min.js" if options.ui? @@ -27,4 +37,4 @@ def download_ujs_driver end end -end +end \ No newline at end of file