Created
March 22, 2015 22:26
-
-
Save jcdarwin/9607c5e8bbf874f04569 to your computer and use it in GitHub Desktop.
A function to create SVG data urls for Ruby SASS
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
# The following goes in your config.rb | |
module Sass::Script::Functions | |
def inline_svg_image(path) | |
real_path = File.join(Compass.configuration.images_path, path.value) | |
svg = data(real_path) | |
encoded_svg = CGI::escape(svg).gsub('+', '%20') | |
data_url = "url('data:image/svg+xml;charset=utf-8," + encoded_svg + "')" | |
Sass::Script::String.new(data_url) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment