Skip to content

Commit

Permalink
Fix #26, update tests bump version 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
FWeinb committed Jun 4, 2014
1 parent c51f0cb commit 8ff5a94
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 52 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

#### 0.2.3
* Fixed lower case `viewBox` in outputted svg (fix [#26](https://github.com/FWeinb/grunt-svgstore/issues/26))

#### 0.2.2
* Fixed a bug where self-closing elements where nested.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-svgstore",
"description": "Merge SVGs from a folder.",
"version": "0.2.2",
"version": "0.2.3",
"homepage": "https://github.com/FWeinb/grunt-svgstore",
"author": {
"name": "Fabrice Weinberg",
Expand Down
29 changes: 7 additions & 22 deletions tasks/svgstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
*/
'use strict';

var genAttrStr = function ( attrs, allowed ) {
var result = '';
Object.keys(attrs).forEach(function (key) {
if ( allowed === undefined || allowed.indexOf(key) >= 0 ) {
result += ' ' + key + '="' + attrs[key] + '"';
}
});
return result;
};

module.exports = function (grunt) {

var crypto = require('crypto');
Expand Down Expand Up @@ -50,11 +40,11 @@ module.exports = function (grunt) {

this.files.forEach(function (file) {

var $resultDocument = cheerio.load('<svg><defs></defs></svg>'),
var $resultDocument = cheerio.load('<svg><defs></defs></svg>', { lowerCaseAttributeNames : false }),
$resultSvg = $resultDocument('svg'),
$resultDefs = $resultDocument('defs').first(),
iconNameViewBoxArray = []; // Used to store information of all icons that are added
// { name : '', attribute : { 'data-viewBox' : ''}}
// { name : '' }

// Merge in SVG attributes from option
for (var attr in options.svg) {
Expand Down Expand Up @@ -112,9 +102,6 @@ module.exports = function (grunt) {
var $title = $('title');
var $desc = $('desc');
var $def = $('defs').first();
var attr = $svg.attr();

var attrStr = genAttrStr(attr, ['viewBox']);

// merge in the defs from this svg in the result defs block.
$resultDefs.append($def.html());
Expand All @@ -130,15 +117,17 @@ module.exports = function (grunt) {
// If there is no title use the filename
title = title || filename;

var resultStr = '<symbol'+attrStr+'>' + '<title>' + title + '</title>';
var resultStr = '<symbol>' + '<title>' + title + '</title>';

// Only add desc if it was set
if ( desc ) { resultStr +='<desc>'+ desc +'</desc>'; }

resultStr += $svg.html() + '</symbol>';

// Create a object
var $res = cheerio.load(resultStr);
var $res = cheerio.load(resultStr, { lowerCaseAttributeNames : false });

$res('symbol').attr('viewBox', $svg.attr('viewBox'));

var graphicId = options.prefix + filename;
// Add ID to the first Element
Expand All @@ -151,10 +140,7 @@ module.exports = function (grunt) {
// Add icon to the demo.html array
if (options.includedemo) {
iconNameViewBoxArray.push({
name: graphicId,
attributes: {
'viewBox': $svg.attr('viewBox')
}
name: graphicId
});
}

Expand Down Expand Up @@ -197,7 +183,6 @@ module.exports = function (grunt) {

var useBlock = '';
iconNameViewBoxArray.forEach(function (item) {
//var attrStr = genAttrStr(item.attributes);
useBlock += '\t\t<svg>\n\t\t\t<use xlink:href="#' + item.name + '"></use>\n\t\t</svg>\n';
});

Expand Down
2 changes: 1 addition & 1 deletion test/expected/default_options.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/expected/formatting.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8ff5a94

Please sign in to comment.