Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. require 'zlib'
  2.  
  3. @@cssPath = '../public/stylesheets/' #relative to where the script is running
  4. @@imagePath = '../public/images/' #relative to where the script is running
  5. @@styleSheets = ['myCssFile1.css', 'AntherCssFile.css']
  6.  
  7. def crc(fileName)
  8. fileName = @@imagePath + fileName.slice(10..-1)
  9. contents = File.read(fileName) ; nil
  10. Zlib.crc32(contents,0).to_s(16)
  11. end
  12.  
  13. @@styleSheets.each do |css|
  14. fileName = @@cssPath + css
  15. file = File.new(fileName, 'r')
  16. lines = []
  17. while line = file.gets
  18. line.gsub! /\.\.\/images\/.*?\.(gif|jpg|png)(\?[a-z\d]+)?/ do |match|
  19. queryIndex = match.index("?")
  20. match = match.slice(0..queryIndex-1) unless queryIndex.nil?
  21. match + "?" + crc(match)
  22. end
  23. lines << line
  24. end
  25. file.close
  26.  
  27. file = File.new(fileName, File::WRONLY|File::TRUNC)
  28. lines.each {|line| file.puts line }
  29. file.close
  30. end
Add Comment
Please, Sign In to add comment