Permalink
Browse files

refactor

  • Loading branch information...
1 parent cdd128b commit b851c9ad5363f774f98a8273d220f1537636b91c @tj tj committed Mar 6, 2013
Showing with 12 additions and 10 deletions.
  1. +12 −10 lib/plugins/inline.js
View
@@ -2,10 +2,12 @@
/**
* Module dependencies.
*/
-var fs = require('fs');
-var path = require('path');
-var mime = require('mime');
-var visit = require('../visit');
+
+var visit = require('../visit')
+ , path = require('path')
+ , mime = require('mime')
+ , fs = require('fs')
+ , read = fs.readFileSync;
/**
* Inline images and fonts.
@@ -22,12 +24,11 @@ var visit = require('../visit');
*
*/
-module.exports = function() {
- if (Array.isArray(arguments[0])) {
- var dirs = arguments[0];
- } else {
- var dirs = Array.prototype.slice.call(arguments);
+module.exports = function(dirs) {
+ if (!Array.isArray(dirs)) {
+ dirs = Array.prototype.slice.call(arguments);
}
+
return function(style, rework){
visit.declarations(style, function(declarations){
declarations.forEach(function(decl){
@@ -39,10 +40,11 @@ module.exports = function() {
}).filter(function(filePath){
return fs.existsSync(filePath)
})[0];
+
if (!file) throw new Error("Can't find `" + name + "` to inline");
var type = mime.lookup(file);
- var base64 = new Buffer(fs.readFileSync(file)).toString('base64');
+ var base64 = new Buffer(read(file)).toString('base64');
return 'url("data:' + type + ';base64,' + base64 + '")';
});
});

0 comments on commit b851c9a

Please sign in to comment.