Skip to content

Instantly share code, notes, and snippets.

@jamesdarvell
Created February 6, 2015 17:55
Show Gist options
  • Save jamesdarvell/9ee60056244325b74083 to your computer and use it in GitHub Desktop.
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).
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