Skip to content

Instantly share code, notes, and snippets.

@jcdarwin
Created March 22, 2015 22:26
Show Gist options
  • Save jcdarwin/9607c5e8bbf874f04569 to your computer and use it in GitHub Desktop.
Save jcdarwin/9607c5e8bbf874f04569 to your computer and use it in GitHub Desktop.
A function to create SVG data urls for Ruby SASS
# 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