Created
September 5, 2014 18:04
-
-
Save marclipovsky/ac3f0d32eb9fd6e0381a to your computer and use it in GitHub Desktop.
Rails/Compass - Rename Compass generated sprite filenames without hash.
This file contains hidden or 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
# encoding: UTF-8 | |
# NOTE: Removing the Compass-generated hash from Compass-generated sprite file | |
# names so that git history doesn't get jacked up. | |
SPRITE_FILE_NAMES = [] | |
# Rename sprites to remove the Compass-generated hash and move it up 1 directory | |
Rails.application.config.compass.on_sprite_saved do |filename| | |
if File.exists?(filename) | |
renamed_file_name = filename.gsub(%r{-s[a-z0-9]{10}\.}, '.') | |
FileUtils.mv(filename, renamed_file_name) | |
SPRITE_FILE_NAMES << [File.basename(filename), File.basename(renamed_file_name)] | |
end | |
end | |
class SpriteNameFixProcessor < ::Tilt::Template | |
def prepare; end | |
# Replace any instances of sprite names with renamed | |
# (sans Compass-generated hash) file name. | |
def evaluate (scope, locals, &block) | |
SPRITE_FILE_NAMES.each do |name, renamed_name| | |
data.gsub!(name, renamed_name) | |
end | |
return data | |
end | |
end | |
Rails.application.assets.register_postprocessor 'text/css', SpriteNameFixProcessor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment