1 | var fs = require('fs'),
|
2 | Parser = require('./parser'),
|
3 | Processor = require('./processor'),
|
4 | EveryCSS;
|
5 |
|
6 | EveryCSS = function () {
|
7 | var processors = [],
|
8 | parser = new Parser();
|
9 |
|
10 | this.use = function (callback, options) {
|
11 | if (typeof callback !== 'function') {
|
12 | throw 'Processors must be a function';
|
13 | }
|
14 | processors.push([callback, options instanceof Object ? options : {}]);
|
15 | return this;
|
16 | };
|
17 |
|
18 | this.process = function (string, success, error) {
|
19 | new Processor(this, parser.parse(string), processors, success, error);
|
20 | };
|
21 | };
|
22 |
|
23 | EveryCSS.prototype.processFile = function (filename, success, error) {
|
24 | var ecss = this;
|
25 | this.filename = filename;
|
26 |
|
27 | fs.readFile(filename, 'utf8', function (err, data) {
|
28 | if (err) {
|
29 | if (typeof error === 'function') {
|
30 | error.call(null, err);
|
31 | }
|
32 | } else {
|
33 | ecss.process(data, success, error);
|
34 | }
|
35 | });
|
36 | };
|
37 |
|
38 | module.exports = EveryCSS; |
\ | No newline at end of file |