Skip to content

Commit

Permalink
some jshint fixes and added ability to exclude class names
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoi committed May 22, 2015
1 parent f779846 commit 2b6349a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
7 changes: 7 additions & 0 deletions examples/example-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@ module.exports = {
'W(1/12)--sm', // fraction with breakpoint
'Bgc(#333)', // hex value
'Bgc(#fff.8)' // hex value + alpha
],
// this is the opposite of the above. There are cases that you may want to tell
// atomizer to ignore class names already defined in `classNames`.
// This is useful when classes are automatically added by the parser or when
// you want to create different atomic css files from the same set of classNames.
'exclude': [
'Fl(end)'
]
};
10 changes: 7 additions & 3 deletions src/atomizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ Atomizer.prototype.getConfig = function (classNames/*:string[]*/, config/*:Atomi
Atomizer.prototype.parseConfig = function (config/*:AtomizerConfig*/, options/*:CSSOptions*/)/*:Tree*/ {
var tree = {};
var classNameSyntax = this.getSyntax(true);
var parsedValues = [];
var warnings = [];
var isVerbose = !!this.verbose;
var classNames = config.classNames;

if (!_.isArray(config.classNames)) { return tree; }
options = options || {};

config.classNames.forEach(function (className) {
if ('exclude' in config) {
classNames = _.difference(classNames, config.exclude);
}

classNames.forEach(function (className) {
var match = XRegExp.exec(className, classNameSyntax);
var rule;
var ruleIndex;
Expand Down Expand Up @@ -450,7 +454,7 @@ Atomizer.prototype.getCss = function (config/*:AtomizerConfig*/, options/*:CSSOp
return;
}

breakPoint = breakPoints && breakPoints[treeo.breakPoint]
breakPoint = breakPoints && breakPoints[treeo.breakPoint];

// this is where we start writing the selector
selector = Atomizer.escapeSelector(treeo.className);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ module.exports = [
"noParams": true,
"styles": {
"position": "absolute !important",
"clip": "rect(1px 1px 1px 1px)",
"*clip": "rect(1px 1px 1px 1px)",
"clip": "rect(1px,1px,1px,1px)",
"padding": "0 !important",
"border": "0 !important",
Expand Down Expand Up @@ -254,7 +254,7 @@ module.exports = [
},
"a[class*=LineClamp]": {
"display": "inline-block",
"display": "-webkit-box",
"display ": "-webkit-box",
"*display": "inline",
"zoom": 1
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ utils.hexToRgb = function (hex/*:string*/)/*:Rgb*/ {
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
};

/**
* helper function to handle merging array of strings
Expand Down
21 changes: 21 additions & 0 deletions tests/atomizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ describe('Atomizer()', function () {
});
expect(result).to.deep.equal(expected);
});
it('returns the expected parsed tree given a config with the exclude key', function () {
var atomizer = new Atomizer();
var expected = {
Fl: [{
className: 'Fl(start)',
declarations: {
float: '__START__'
}
}]
};
var result = atomizer.parseConfig({
classNames: [
'Fl(end)',
'Fl(start)'
],
exclude: [
'Fl(end)'
]
});
expect(result).to.deep.equal(expected);
});
it('returns empty object if invalid class names have been passed', function () {
var atomizer = new Atomizer();
var expected = {};
Expand Down

0 comments on commit 2b6349a

Please sign in to comment.