Skip to content

Commit

Permalink
feat: add nesting addon
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 13, 2018
1 parent ad64849 commit ce8b5dc
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions addon/nesting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

module.addon = function (renderer) {
renderer.selector = function (parentSelectors, selector) {
var parents = parentSelectors.split(',');
var result = [];
var selectors = selector.split(',');
var len1 = parents.length;
var len2 = selectors.length;
var i, j, part1, part2, sel, pos, parent, replacedSelector;

for (i = 0; i < len2; i++) {
sel = selectors[i];
pos = sel.indexOf('&');

if (pos > -1) {
part1 = sel.substr(0, pos);
part2 = sel.substr(pos + 1);

for (j = 0; j < len1; j++) {
parent = parents[j];
replacedSelector = part1 + parent + part2;

result.push(replacedSelector);
}
} else {
for (j = 0; j < len1; j++) {
parent = parents[j];

if (parent) {
result.push(parent + ' ' + sel);
} else {
result.push(sel);
}
}
}
}

return result.join(',');
};
};

0 comments on commit ce8b5dc

Please sign in to comment.