Skip to content

Instantly share code, notes, and snippets.

@lautis
Created August 9, 2011 13:11
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 lautis/1134000 to your computer and use it in GitHub Desktop.
Save lautis/1134000 to your computer and use it in GitHub Desktop.
Rails 3.1 CSS compressor to replace url(asset.png) with real asset path
class CssAssetPathCompressor
include Sprockets::Helpers::RailsHelper
ReplaceRexeg = /url\(["']?([^\)\?"']+)(\?[^"']*)?["']?\)/i
def initialize(compressor)
@compressor = compressor
end
def compress(css)
rewrite(css)
@compressor.compress(css)
end
protected
def rewrite(css)
css.gsub(ReplaceRexeg) do |match|
rewrite_asset_url(match)
end
end
def rewrite_asset_url(match)
if match[1]
else
end
end
def config
Rails.application.config
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment