FWeinb/grunt-svgstore — pull request #66 by corpulentcoffee (2014-10-15 21:15:22+00:00)
Title: Optionally derive symbol viewBox from its source SVG width/height

Hello! Thank you for the wonderful Grunt plug-in.

I have a collection of SVGs from Inkscape of *varying sizes* that do not explicitly advertise a `viewBox` *but do* advertise their `width` and `height` in pixels (similar to [cleanup.svg](https://raw.githubusercontent.com/FWeinb/grunt-svgstore/master/test/fixtures/cleanup.svg) in your fixture data). I want to use these with consistent and simple markup like ``, so I need a `viewBox` set on each of the generated symbols. If not for the fact that the SVGs have varying sizes, I would be able to use `options.symbol.viewBox` for this.

My first attempt to solve this used [`grunt-dom-munger` to add the `viewBox` attribute](https://gist.github.com/corpulentcoffee/09318df3628e7a930608/050c6186be256858bc9fa1da5492e90cbc39fd71#file-gruntfile-js) before passing the SVGs along to `grunt-svgstore`, but this adds a lot of bloat to `Gruntfile.js`. Since `grunt-svgstore` already attempts to set `viewBox` on the generated symbols, I was wondering if it could optionally derive it from the `width`/`height` if it doesn't find an explicit `viewBox` on the source SVG. The result would [eliminate the need for `grunt-dom-munger`](https://gist.github.com/corpulentcoffee/09318df3628e7a930608/ab9cbe718f4188e6f9b2d557b3da30f4cf18b122#file-gruntfile-js) on my end.

Let me know if you have any thoughts on this *or* if you happen to know a better way forward.

Cheers,
Dave