Created
July 11, 2017 16:42
-
-
Save nicocedron/01fdc2fafc998f077d73fc5c5ad7dd38 to your computer and use it in GitHub Desktop.
Wicked PDF Fonts to base64
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
@font-face { | |
font-family: 'Glyphicons Halflings'; | |
src: url(asset_base64('admin/fonts/glyphicons-halflings-regular.eot')); | |
src: url(asset_base64('admin/fonts/glyphicons-halflings-regular.eot')) format('embedded-opentype'), | |
url(asset_base64('admin/fonts/glyphicons-halflings-regular.woff2')) format('woff2'), | |
url(asset_base64('admin/fonts/glyphicons-halflings-regular.woff')) format('woff'), | |
url(asset_base64('admin/fonts/glyphicons-halflings-regular.ttf')) format('truetype'), | |
url(asset_base64('admin/fonts/glyphicons-halflings-regular.svg')) format('svg'); | |
} |
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
require 'sass' | |
module Sprockets::SassFunctions | |
def asset_base64(path) | |
asset = Rails.application.assets.find_asset(path.value) | |
throw "Could not find asset '#{path}'" if asset.nil? | |
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "") | |
code = "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}" | |
::Sass::Script::String.new(code, :string) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment