# Inline SVG
Styling a SVG document with CSS for use on the web is most reliably achieved by
[adding classes to the document and
embedding](http://css-tricks.com/using-svg/) it inline in the HTML.
This gem is a little Rails helper method (`inline_svg`) that reads an SVG document (via Sprockets, so works with the Rails Asset Pipeline), applies a CSS class attribute to the root of the document and
then embeds it into a view.
Inline SVG supports [Rails version 4.0.4](http://weblog.rubyonrails.org/2014/3/14/Rails-4-0-4-has-been-released/) and newer.
Want to embed SVGs with Javascript? You might like [RemoteSvg](https://github.com/jamesmartin/remote-svg), which features similar transforms but can also load SVGs from remote URLs (like S3 etc.).
## Changelog
This project adheres to [Semantic Versioning](http://sermver.org). All notable changes are documented in the
[CHANGELOG](https://github.com/jamesmartin/inline_svg/blob/master/CHANGELOG.md).
## Installation
Add this line to your application's Gemfile:
gem 'inline_svg'
And then execute:
$ bundle
Or install it yourself as:
$ gem install inline_svg
## Usage
```
inline_svg(file_name, options={})
```
The `file_name` can be a full path to a file, the file's basename or an `IO`
object. The
actual path of the file on disk is resolved using
[Sprockets](://github.com/sstephenson/sprockets) (when available), a naive file finder (`/public/assets/...`) or in the case of `IO` objects the SVG data is read from the object.
This means you can pre-process and fingerprint your SVG files like other Rails assets, or choose to find SVG data yourself.
Here's an example of embedding an SVG document and applying a 'class' attribute in
HAML:
```haml
!!! 5
%html
%head
%title Embedded SVG Documents
%body
%h1 Embedded SVG Documents
%div
= inline_svg "some-document.svg", class: 'some-class'
```
Here's some CSS to target the SVG, resize it and turn it an attractive shade of
blue:
```css
.some-class {
display: block;
margin: 0 auto;
fill: #3498db;
width: 5em;
height: 5em;
}
```
## Options
key | description
:---------------------- | :----------
`id` | set a ID attribute on the SVG
`class` | set a CSS class attribute on the SVG
`data` | add data attributes to the SVG (supply as a hash)
`size` | set width and height attributes on the SVG
Can also be set using `height` and/or `width` attributes, which take precedence over `size`
Supplied as "{Width} * {Height}" or "{Number}", so "30px*45px" becomes `width="30px"` and `height="45px"`, and "50%" becomes `width="50%"` and `height="50%"`
`title` | add a \