Created
January 22, 2014 16:55
-
-
Save guilleiguaran/8562426 to your computer and use it in GitHub Desktop.
Sprockets preprocessor for asset paths
This file contains 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
body{background-image:url("/assets/background-0539f790ccc171714d5ad38f5524423e.jpg")} |
This file contains 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
body | |
{ | |
background-image: url('/assets/background.jpg'); | |
} |
This file contains 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 AssetPathPreprocessor < Sprockets::Processor | |
def evaluate(context, locals) | |
data.gsub(%r{["|']/assets/(.+)["|']}) do | |
'"' + context.asset_path($1) + '"' | |
end | |
end | |
end |
This file contains 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
require 'asset_path_preprocessor' | |
Rails.application.assets.register_preprocessor('application/javascript', AssetPathPreprocessor) | |
Rails.application.assets.register_preprocessor('text/css', AssetPathPreprocessor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment