Skip to content

Commit

Permalink
change to array some
Browse files Browse the repository at this point in the history
  • Loading branch information
cuth committed Jun 19, 2015
1 parent dff48e5 commit f7b0da3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
18 changes: 7 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ module.exports = postcss.plugin('postcss-pxtorem', function (options) {
css.eachDecl(function (decl, i) {
if (propWhiteList.indexOf(decl.prop) === -1) return;

var selector = decl.parent.selector;
var match = false;
for (var j=0; j<selectorBlackList.length; j++) {
match = selector.match(selectorBlackList[j]);
if (match) {
break;
}
}
if (match) {
return;
}
if (blacklistedSelector(selectorBlackList, decl.parent.selector)) return;

var rule = decl.parent;
var value = decl.value;
Expand Down Expand Up @@ -76,3 +66,9 @@ function remExists(decls, prop, value) {
return (decl.prop === prop && decl.value === value);
});
}

function blacklistedSelector(blacklist, selector) {
return blacklist.some(function (regex) {
return selector.match(regex);
});
}
22 changes: 11 additions & 11 deletions spec/pxtorem-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ var css = '.rule { font-size: 15px }';

describe('pxtorem', function () {

it('should ignore selectors in the selector black list', function () {
var rules = '.rule { font-size: 15px } .rule2 { font-size: 15px }';
var expected = '.rule { font-size: 0.9375rem } .rule2 { font-size: 15px }';
var options = {
selector_black_list: ['.rule2']
};
var processed = postcss(pxtorem(options)).process(rules).css;

expect(processed).toBe(expected);
});

it('should replace the px unit with rem', function () {
var processed = postcss(pxtorem()).process(css).css;
var expected = '.rule { font-size: 0.9375rem }';
Expand Down Expand Up @@ -60,6 +49,17 @@ describe('pxtorem', function () {
expect(processed).toBe(expected);
});

it('should ignore selectors in the selector black list', function () {
var rules = '.rule { font-size: 15px } .rule2 { font-size: 15px }';
var expected = '.rule { font-size: 0.9375rem } .rule2 { font-size: 15px }';
var options = {
selector_black_list: ['.rule2']
};
var processed = postcss(pxtorem(options)).process(rules).css;

expect(processed).toBe(expected);
});

it('should leave fallback pixel unit with root em value', function () {
var options = {
replace: false
Expand Down

0 comments on commit f7b0da3

Please sign in to comment.