Skip to content

Instantly share code, notes, and snippets.

@toamitkumar
Created November 30, 2010 03:43
Show Gist options
  • Save toamitkumar/721113 to your computer and use it in GitHub Desktop.
Save toamitkumar/721113 to your computer and use it in GitHub Desktop.
task to time stamp images in css
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