@@ -9,7 +9,7 @@ task :guard_version do
99 def check_version ( file , pattern , constant )
1010 body = File . read ( "vendor/assets/javascripts/#{ file } " )
1111 match = body . match ( pattern ) or abort "Version check failed: no pattern matched in #{ file } "
12- file_version = body . match ( pattern ) [ 1 ]
12+ file_version = match [ 1 ]
1313 constant_version = Jquery ::Rails . const_get ( constant )
1414
1515 unless constant_version == file_version
@@ -20,29 +20,19 @@ task :guard_version do
2020 check_version ( 'jquery.js' , /jQuery JavaScript Library v([\S ]+)/ , 'JQUERY_VERSION' )
2121end
2222
23+ desc "Update jQuery versions"
2324task :update_jquery do
24- puts "Downloading jquery.js"
25- puts `curl -o vendor/assets/javascripts/jquery.js http://code.jquery.com/jquery.js`
26- puts "Downloading jquery.min.js"
27- puts `curl -o vendor/assets/javascripts/jquery.min.js http://code.jquery.com/jquery.min.js`
28- puts "Downloading jquery.min.map"
29- puts `curl -o vendor/assets/javascripts/jquery.min.map http://code.jquery.com/jquery.min.map`
30-
31- puts "Updating version.rb"
32- version = false
33- File . foreach ( 'vendor/assets/javascripts/jquery.js' ) do |line |
34- version = line . match ( /jQuery JavaScript Library v([\S ]+)/ )
35- version = version && version [ 1 ]
36- break if version
37- end
38-
39- version_path = 'lib/jquery/rails/version.rb'
40- lines = IO . readlines ( version_path ) . map do |line |
41- line . gsub ( /JQUERY_VERSION = "([\d \. ]+)"/ , "JQUERY_VERSION = \" #{ version } \" " )
42- end
43- File . open ( version_path , 'w' ) do |file |
44- file . puts lines
25+ def download_jquery ( filename , version )
26+ suffix = "-#{ version } "
27+
28+ puts "Downloading #{ filename } .js"
29+ puts `curl -o vendor/assets/javascripts/#{ filename } .js https://code.jquery.com/jquery#{ suffix } .js`
30+ puts "Downloading #{ filename } .min.js"
31+ puts `curl -o vendor/assets/javascripts/#{ filename } .min.js https://code.jquery.com/jquery#{ suffix } .min.js`
32+ puts "Downloading #{ filename } .min.map"
33+ puts `curl -o vendor/assets/javascripts/#{ filename } .min.map https://code.jquery.com/jquery#{ suffix } .min.map`
4534 end
4635
36+ download_jquery ( 'jquery' , Jquery ::Rails ::JQUERY_VERSION )
4737 puts "\e [32mDone!\e [0m"
4838end
0 commit comments