Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :jquery do
- desc "Update jquery libraries to use 'jQuery.' rather than '$.'"
- task :devalue => :environment do
- prototype_js = %w[
- application.js
- controls.js
- dragdrop.js
- effects.js
- prototype.js
- ]
- Dir.glob(RAILS_ROOT + '/public/javascripts/*.js').each do |file|
- unless prototype_js.include?(File.basename(file))
- File.open(file) do |jfile|
- js = jfile.read
- if js["function($)"]
- File.open(file+'.devalued', 'w') {|f| f.write(js) } # Make backup file.js.devalued
- js.gsub!("function($)", "function(jQuery)")
- js.gsub!("$.", "jQuery.")
- js.gsub!("$(", "jQuery(")
- js.gsub!("$[", "jQuery[")
- File.open(file, 'w') {|f| f.write(js) }
- puts "Devalued #{file}"
- puts "Backed up to #{file}.devalued"
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment