Skip to content

Commit

Permalink
added 'strict' option (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
bezoerb committed Dec 10, 2015
1 parent 88253d9 commit 22cd7a5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ Default: `false`
Required: `false`

Use Base64 encoding for svgs.

####strict
Type: `bool`
Default: `false`
Required: `false`

Fail on error
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = postcss.plugin('postcss-image-inliner', function (opts) {
opts = defaults(opts || {}, {
assetPaths: [],
maxFileSize: 10240,
b64Svg: false
b64Svg: false,
strict: false
});

if (isString(opts.assetPaths)) {
Expand Down Expand Up @@ -85,10 +86,16 @@ module.exports = postcss.plugin('postcss-image-inliner', function (opts) {
debug(url, 'successfully replaced with ', data[url]);
} else {
debug(url, 'failed');
if (opts.strict) {
throw new Error('No file found for ' + url);
}
}
}));
}).catch(function (err) {
debug(err);
return new Promise(function (resolve, reject) {
reject(err);
});
});
};
});
3 changes: 3 additions & 0 deletions test/fixtures/styles/missing.in.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.shorthand {
background: transparent url("../images/missing.gif") no-repeat left top scroll;
}
3 changes: 3 additions & 0 deletions test/fixtures/styles/missing.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.shorthand {
background: transparent url("../images/missing.gif") no-repeat left top scroll;
}
15 changes: 14 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var test = function (input, output, opts, done) {
expect(result.warnings()).to.be.empty;
done();
}).catch(function (error) {
console.log(error);
done(error);
});
};
Expand Down Expand Up @@ -75,4 +74,18 @@ describe('postcss-image-inliner', function () {
it('should consider base64Svg option', function (done) {
test('b64svg.in.css', 'b64svg.out.css', { b64Svg: true, maxFileSize: 0 }, done);
});

it('should do nothing on missing files in non strict mode', function (done) {
test('missing.in.css', 'missing.out.css', { }, done);
});

it('should fail on missing files in strict mode', function (done) {
test('missing.in.css', 'missing.out.css', { strict: true }, function (error) {
if (error) {
done();
} else {
done(new Error('Should fail'));
}
});
});
});

0 comments on commit 22cd7a5

Please sign in to comment.