Created
February 6, 2015 17:55
-
-
Save jamesdarvell/9ee60056244325b74083 to your computer and use it in GitHub Desktop.
A middleman app helper method for creating a base 64 encoded uri for an asset (to inline it).
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
module DataUriInlining | |
def asset_data_uri(name) | |
asset = sprockets.find_asset(name) | |
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "") | |
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment