Skip to content

Commit b820540

Browse files
pwnallindirect
authored andcommitted
Slightly better version selection for jquery and jquery UI.
1 parent bb0f840 commit b820540

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/generators/jquery/install/install_generator.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class InstallGenerator < ::Rails::Generators::Base
44
desc "This generator downloads and installs jQuery, jQuery-ujs HEAD, and (optionally) jQuery UI 1.8.4"
55
class_option :ui, :type => :boolean, :default => false, :desc => "Whether to Include JQueryUI"
66
class_option :version, :type => :string, :default => "1.4.1", :desc => "Which version of JQuery to fetch"
7-
@@versions = %w( 1.4.2 1.4.1 1.4.0 1.3.2 1.3.1 1.3.0 1.2.6 )
7+
@@versions = %w( 1.4.3 1.4.2 1.4.1 1.4.0 1.3.2 1.3.1 1.3.0 1.2.6 )
88

99

1010
def remove_prototype
@@ -20,14 +20,22 @@ def download_jquery
2020
get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.min.js", "public/javascripts/jquery.min.js"
2121
get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.js", "public/javascripts/jquery.js"
2222
else
23-
puts "JQuery #{options.version} is invalid; fetching #{@@versions[1]} instead."
24-
get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[1]}/jquery.min.js", "public/javascripts/jquery.min.js"
25-
get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[1]}/jquery.js", "public/javascripts/jquery.js"
23+
# Try to get it anyway
24+
begin
25+
puts "Trying to fetch JQuery version #{options.version}, even though I don't know about it.'"
26+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.min.js", "public/javascripts/jquery.min.js"
27+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.js", "public/javascripts/jquery.js"
28+
puts "Success"
29+
rescue
30+
puts "JQuery #{options.version} is invalid; fetching #{@@versions[2]} instead."
31+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[2]}/jquery.min.js", "public/javascripts/jquery.min.js"
32+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[2]}/jquery.js", "public/javascripts/jquery.js"
33+
end
2634
end
2735

2836
# Downloading latest jQueryUI minified
29-
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js", "public/javascripts/jquery-ui.min.js" if options.ui?
30-
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js", "public/javascripts/jquery-ui.js" if options.ui?
37+
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js", "public/javascripts/jquery-ui.min.js" if options.ui?
38+
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js", "public/javascripts/jquery-ui.js" if options.ui?
3139
end
3240

3341
def download_ujs_driver

0 commit comments

Comments
 (0)