Created
August 9, 2011 13:11
-
-
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
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
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