Skip to content
This repository has been archived by the owner on Mar 28, 2018. It is now read-only.

Commit

Permalink
Add first pass functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
johno committed May 6, 2015
1 parent 3d54f9f commit 41256d2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
21 changes: 17 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
'use strict';

module.exports = function postcssCssstats(options) {
options = options || {};
var _ = require('lodash');
var postcss = require('postcss');
var cssstats = require('cssstats');

return true;
};
module.exports = postcss.plugin('cssstats', function(options, callback) {
if (_.isFunction(options)) {
callback = options;
options = {};
} else {
options = options || {};
callback = callback || _.noop;
}

return function(css, postcssResult) {
// XXX TODO: cssstats should also be able to handle an AST
callback(cssstats(css.toString()));
};
});
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
"url": "https://github.com/cssstats/postcss-cssstats.git"
},
"keywords": [

"cssstats",
"css",
"stats",
"statistics",
"postcss",
"postcss-plugin"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/cssstats/postcss-cssstats/issues"
},
"homepage": "https://github.com/cssstats/postcss-cssstats",
"dependencies": {},
"dependencies": {
"cssstats": "^1.5.1",
"lodash": "^3.8.0",
"postcss": "^4.1.9"
},
"devDependencies": {
"is-present": "0.0.1",
"mocha": "*"
}
}
7 changes: 7 additions & 0 deletions test/fixtures/basic.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.foo {
color: tomato;
}

.bar .baz {
color: hotpink;
}
18 changes: 16 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
'use strict';

var fs = require('fs');
var assert = require('assert');
var postcss = require('postcss');
var isPresent = require('is-present');
var postcssCssstats = require('..');

describe('postcss-cssstats', function() {

it('should do something awesome', function() {
assert.equal(postcssCssstats(), true);
it('should return a stats object', function(done) {
postcss()
.use(postcssCssstats({}, function(stats) {
assert.ok(isPresent(stats));
}))
.process(fixture('basic'))
.then(function() {
done();
});
});
});

function fixture(name) {
return fs.readFileSync('test/fixtures/' + name + '.css', 'utf8').toString();
}

0 comments on commit 41256d2

Please sign in to comment.