Skip to content

Commit

Permalink
Allow multiple selectors for ID / class namespacing (closes svg-sprit…
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed May 14, 2016
1 parent c2c5658 commit 01dd807
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Breaking change: Dropped support for Node.js < 4.0 and io.js
* Set sprite size in example document ([#138](https://github.com/jkphl/svg-sprite/issues/138))
* Added XML entity resolution ([#118](https://github.com/jkphl/svg-sprite/issues/118))
* Allow multiple selectors for ID / class namespacing ([#109](https://github.com/jkphl/svg-sprite/issues/109))

## 1.2.19 Maintenance release (2016-01-11)
* Updated dependencies
Expand Down
13 changes: 6 additions & 7 deletions lib/svg-sprite/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ SVGShape.prototype._replaceIdAndClassnameReferencesInCssSelectors = function(str
classnames.push(classname);
}
};
var idOrClassSubstitution = function(sel){
// If ID substitution should be applied: Search for an ID
var idOrClassSubstitution = function(sel){
// If ID substitution should be applied: Search for an ID
if (('id' in sel.rule) && (substIds !== null) && (('#' + sel.rule.id) in substIds)) {
ids.push(sel.rule.id);
}
Expand All @@ -796,17 +796,16 @@ SVGShape.prototype._replaceIdAndClassnameReferencesInCssSelectors = function(str
if (('classNames' in sel.rule) && (substClassnames !== null) && _.isArray(sel.rule.classNames)) {
sel.rule.classNames.forEach(classnameFilter);
}
};
};

// If there are multiple subselectors, substitute all of them
if ('selectors' in sel) {
sel.selectors.forEach(function(subsel){
idOrClassSubstitution(subsel);
}, this);
sel.selectors.forEach(idOrClassSubstitution);
}

// While there are nested rules: Substitute and recurse
while ((typeof(sel) === 'object') && ('rule' in sel)) {
idOrClassSubstitution(sel);
// Recurse
sel = sel.rule;
}

Expand Down
23 changes: 23 additions & 0 deletions test/fixture/svg/special/coin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test/fixture/svg/special/new.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 01dd807

Please sign in to comment.