Guest User

Untitled

a guest
May 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. namespace :jquery do
  2. desc "Update jquery libraries to use 'jQuery.' rather than '$.'"
  3. task :devalue => :environment do
  4. prototype_js = %w[
  5. application.js
  6. controls.js
  7. dragdrop.js
  8. effects.js
  9. prototype.js
  10. ]
  11. Dir.glob(RAILS_ROOT + '/public/javascripts/*.js').each do |file|
  12. unless prototype_js.include?(File.basename(file))
  13. File.open(file) do |jfile|
  14. js = jfile.read
  15. if js["function($)"]
  16. File.open(file+'.devalued', 'w') {|f| f.write(js) } # Make backup file.js.devalued
  17. js.gsub!("function($)", "function(jQuery)")
  18. js.gsub!("$.", "jQuery.")
  19. js.gsub!("$(", "jQuery(")
  20. js.gsub!("$[", "jQuery[")
  21. File.open(file, 'w') {|f| f.write(js) }
  22. puts "Devalued #{file}"
  23. puts "Backed up to #{file}.devalued"
  24. end
  25. end
  26. end
  27. end
  28. end
  29. end
Add Comment
Please, Sign In to add comment