Permalink
Browse files

refactor

  • Loading branch information...
1 parent 0ceeae2 commit 81f1e867459b6f152bd9c7c353cac48c1d712701 @tj tj committed Mar 8, 2013
Showing with 6 additions and 7 deletions.
  1. +6 −7 lib/plugins/inline.js
View
@@ -7,7 +7,8 @@ var func = require('./function')
, path = require('path')
, mime = require('mime')
, fs = require('fs')
- , read = fs.readFileSync;
+ , read = fs.readFileSync
+ , exists = fs.existsSync;
/**
* Inline images and fonts.
@@ -31,14 +32,12 @@ module.exports = function(dirs) {
return func({ inline: inline });
- function inline(fileName){
+ function inline(filename){
var file = dirs.map(function(dir) {
- return path.join(dir, fileName);
- }).filter(function(filePath){
- return fs.existsSync(filePath)
- })[0];
+ return path.join(dir, filename);
+ }).filter(exists)[0];
- if (!file) throw new Error("Can't find `" + fileName + "` to inline");
+ if (!file) throw new Error('inline(): failed to find "' + filename + '"');
var type = mime.lookup(file);
var base64 = new Buffer(read(file)).toString('base64');

0 comments on commit 81f1e86

Please sign in to comment.