Skip to content

Instantly share code, notes, and snippets.

@co2bo
Forked from jamesdarvell/data_uri_inlining.rb
Created February 25, 2016 09:19
Show Gist options
  • Save co2bo/5b852c6c91d7ef983fa6 to your computer and use it in GitHub Desktop.
Save co2bo/5b852c6c91d7ef983fa6 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