https://github.com/franzheidl/sass-inline-svg
Inline url-encoded SVG with Sass. Optional variable string replacement included!
https://github.com/franzheidl/sass-inline-svg
inline-svg ruby sass sass-inline-svg svg svg-icons
Last synced: 12 months ago
JSON representation
Inline url-encoded SVG with Sass. Optional variable string replacement included!
- Host: GitHub
- URL: https://github.com/franzheidl/sass-inline-svg
- Owner: franzheidl
- License: mit
- Created: 2015-08-06T21:51:41.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-10-11T13:49:19.000Z (over 8 years ago)
- Last Synced: 2025-07-15T06:42:03.773Z (12 months ago)
- Topics: inline-svg, ruby, sass, sass-inline-svg, svg, svg-icons
- Language: Ruby
- Size: 13.7 KB
- Stars: 21
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Sass-Inline-Svg
[](http://badge.fury.io/rb/sass_inline_svg)
Inline url-encoded SVG with Sass. Optional variable string replacement included!
This is a Ruby Gem to be used with Ruby Sass, a version of this for node/npm-based environments with node-sass lives here: [sass-inline-svg-utf8](https://github.com/franzheidl/sass-inline-svg-utf8)
## Installation
gem install sass_inline_svg
Add this line to your application's Gemfile:
gem 'sass_inline_svg'
## Usage
Sass-inline-svg adds a `inline_svg` function you can use with Sass. It url-encodes the contents of the specified file and inlines it in your CSS (Url-encoded SVG is about 30% smaller than base64).
###Basic
.my-thing {
background-image: inline_svg('my-file.svg');
}
When working with plain Sass, you'll have to use the full path to the svg file, when using Rails the path will be resolved by the Rails asset pipeline.
###Replacing Variable Strings
Replacing variable strings in SVG when inlining them with Sass makes sense e.g. if you need multiple variants of the same graphic with different fill colors.
With Sass-Inline-Svg you only need __one__ source svg file with a variable string for `fill`:
…
…
The variants needed can be created during inlinig with Sass. Pass a Sass map of replacements as a second parameter:
.my-thing {
background-image: inline_svg('my-file.svg', ( fillcolor: '#fff' ));
}
This will replace all occurences of `fillcolor` in your SVG with `#fff`:
…
…
__Note:__ If you use `$`- or `@`-prefixed variable names in your SVG or if you want to replace an existing hex color, you'll have to quote the keys in your raplement Sass map:
.my-thing {
background-image: inline_svg('my-file.svg', ( '$fillcolor': '#fff' ));
}
or
.my-thing {
background-image: inline_svg('my-file.svg', ( '#000': '#fff' ));
}