1 |
|
2 | 'use strict';
|
3 |
|
4 | var path = require('path');
|
5 | var gutil = require('gulp-util');
|
6 | var through2 = require('through2');
|
7 | var PluginError = gutil.PluginError;
|
8 | var ResourceEmbedder = require('./lib/resource-embedder2');
|
9 |
|
10 | module.exports = function (options) {
|
11 | return through2.obj(function (file, enc, cb) {
|
12 |
|
13 | var filepath = file.path;
|
14 |
|
15 |
|
16 | if (file.isNull()) {
|
17 | this.emit('error', new PluginError('gulp-embed', 'File not found: "' + filepath + '"'));
|
18 | return cb();
|
19 | }
|
20 |
|
21 | var embedder = new ResourceEmbedder(filepath, options);
|
22 |
|
23 | embedder.get(function (markup) {
|
24 | var f = new gutil.File({
|
25 | cwd: '',
|
26 | path: file.relative,
|
27 | contents: new Buffer(markup)
|
28 | });
|
29 |
|
30 | this.push(f);
|
31 | cb();
|
32 | }.bind(this));
|
33 |
|
34 | });
|
35 | }; |
\ | No newline at end of file |