diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 62f5df7..270e816 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,14 @@ Convert and replace image-files within your DOM/HTML to base64-encoded data. +## Options + +```js +img64({ + baseDir: 'path/to/images' +}) +``` + ## Example ##### gulpfile.js @@ -42,7 +50,6 @@ gulp.task('default', function () { ... ``` - ### License MIT © 247even diff --git a/index.js b/index.js index 115a3db..3f18f96 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,8 @@ var fs = require('fs'); var path = require('path'); var mime = require('mime'); -module.exports = function() { +module.exports = function(opts) { + opts = opts || {} // create a stream through which each file will pass return through.obj(function(file, enc, callback) { @@ -29,10 +30,9 @@ module.exports = function() { var ssrc = this.attr('src'); var isdata = ssrc.indexOf("data"); if (ssrc != "" && typeof ssrc != 'undefined' && isdata !== 0) { - var spath = path.join(file.base, ssrc); + var spath = path.join(opts.baseDir || file.base, ssrc); var mtype = mime.lookup(spath); if (mtype != 'application/octet-stream') { - console.log(mtype); var sfile = fs.readFileSync(spath); var simg64 = new Buffer(sfile).toString('base64'); this.attr('src', 'data:' + mtype + ';base64,' + simg64); diff --git a/test/fixtures/clock.png b/test/fixtures/custom_dir/elsewhere/clock2.png similarity index 100% rename from test/fixtures/clock.png rename to test/fixtures/custom_dir/elsewhere/clock2.png diff --git a/test/fixtures/custom_dir/input.html b/test/fixtures/custom_dir/input.html new file mode 100644 index 0000000..3ccce45 --- /dev/null +++ b/test/fixtures/custom_dir/input.html @@ -0,0 +1,3 @@ +
+
+
diff --git a/test/fixtures/default_dir/clock.png b/test/fixtures/default_dir/clock.png
new file mode 100644
index 0000000..fa3c8a7
Binary files /dev/null and b/test/fixtures/default_dir/clock.png differ
diff --git a/test/fixtures/input.html b/test/fixtures/default_dir/input.html
similarity index 80%
rename from test/fixtures/input.html
rename to test/fixtures/default_dir/input.html
index 0184554..85f5280 100644
--- a/test/fixtures/input.html
+++ b/test/fixtures/default_dir/input.html
@@ -1,3 +1,3 @@
-
\ No newline at end of file
+