Skip to content

Instantly share code, notes, and snippets.

@rdsaunders
Created January 19, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdsaunders/7b8d8ebc54a65a8f0088 to your computer and use it in GitHub Desktop.
Save rdsaunders/7b8d8ebc54a65a8f0088 to your computer and use it in GitHub Desktop.
Remove the random string in the sprite filename If you don’t want the random string that’s appended to the filename when a new sprite is created, here’s how to remove it. You will need to add this to config.rb inside your Compass project.
# Make a copy of sprites with a name that has no uniqueness of the hash.
on_sprite_saved do |filename|
if File.exists?(filename)
FileUtils.cp filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
# Note: Compass outputs both with and without random hash images.
# To not keep the one with hash, add: (Thanks to RaphaelDDL for this)
FileUtils.rm_rf(filename)
end
end
# Replace in stylesheets generated references to sprites
# by their counterparts without the hash uniqueness.
on_stylesheet_saved do |filename|
if File.exists?(filename)
css = File.read filename
File.open(filename, 'w+') do |f|
f << css.gsub(%r{-s[a-z0-9]{10}\.png}, '.png')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment