Created
November 30, 2010 03:43
-
-
Save toamitkumar/721113 to your computer and use it in GitHub Desktop.
task to time stamp images in css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :timestamp do | |
file_list.each do |file_name| | |
file_path = "#{RAILS_ROOT}/public/stylesheets/"+file_name | |
file = File.new(file_path) | |
temp_file_path = "#{RAILS_ROOT}/public/stylesheets/"+file_name+"_1" | |
temp_file = File.new(temp_file_path, File::CREAT|File::TRUNC|File::RDWR, 0644) | |
file.readlines.map {|line| | |
line = line.gsub(/\.(ico|gif|jpe?g|png)/) {|s| s+'?'+rand(1000000000000)} | |
temp_file.write line | |
} | |
file.close | |
File.delete(file_path) | |
temp_file.close | |
File.rename(temp_file_path, file_path) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment