README.md in inline_svg-1.2.1 vs README.md in inline_svg-1.2.2

- old
+ new

@@ -1,8 +1,8 @@ # Inline SVG -[![CircleCI](https://circleci.com/gh/jamesmartin/inline_svg.svg?style=svg)](https://circleci.com/gh/jamesmartin/inline_svg) +[![Build Status](https://travis-ci.org/jamesmartin/inline_svg.svg?branch=master)](https://travis-ci.org/jamesmartin/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. @@ -69,14 +69,14 @@ width: 5em; height: 5em; } ``` -## Options +## 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 <br/> Can also be set using `height` and/or `width` attributes, which take precedence over `size` <br/> 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 \<title\> node inside the top level of the SVG document @@ -131,14 +131,13 @@ # Sets the `custom` attribute on the root SVG element to supplied value # Remember to return a document, as this will be passed along the transformation chain class MyCustomTransform < InlineSvg::CustomTransformation def transform(doc) - doc = Nokogiri::XML::Document.parse(doc.to_html) - svg = doc.at_css 'svg' - svg['custom'] = value - doc + with_svg(doc) do |svg| + svg["custom"] = value + end end end ``` Add the custom configuration in an initializer (E.g. `./config/initializers/inline_svg.rb`): @@ -254,9 +253,34 @@ ``` **Note:** Paths are read recursively, so think about keeping your SVG assets restricted to as few paths as possible, and using the filter option to further restrict assets to only those likely to be used by `inline_svg`. + +## Missing SVG Files + +If the specified SVG file cannot be found a helpful, empty SVG document is +embedded into the page instead. The embedded document contains a single comment +displaying the filename of the SVG image the helper tried to render: + +```html +<svg><!-- SVG file not found: 'some-missing-file.svg' --></svg> +``` + +You may apply a class to this empty SVG document by specifying the following +configuration: + +```rb +InlineSvg.configure do |config| + config.svg_not_found_css_class = 'svg-not-found' +end +``` + +Which would instead render: + +```html +<svg class='svg-not-found'><!-- SVG file not found: 'some-missing-file.svg' --></svg> +``` ## Contributing 1. Fork it ( [http://github.com/jamesmartin/inline_svg/fork](http://github.com/jamesmartin/inline_svg/fork) ) 2. Create your feature branch (`git checkout -b my-new-feature`)