Comparing version 0.8.0 to 0.9.0
50
index.js
@@ -5,3 +5,3 @@ 'use strict'; | ||
var gutil = require('gulp-util'); | ||
var tpl = require('lodash.template'); | ||
var consolidate = require('consolidate'); | ||
var fs = require('fs'); | ||
@@ -13,5 +13,9 @@ var extend = require('node.extend'); | ||
function compile(file, contents, template, data, options){ | ||
function compile(file, contents, template, data, options, callback){ | ||
options = options || {}; | ||
if (!options.engine) { | ||
options.engine = 'lodash'; | ||
} | ||
data = data || {}; | ||
@@ -23,8 +27,9 @@ data.contents = contents; | ||
try { | ||
if (file.path.match(/json$/)) | ||
data.contents = JSON.parse(contents) | ||
else if (file.path.match(/ya?ml$/)) | ||
data.contents = require('js-yaml').safeLoad(contents) | ||
if (file.path.match(/json$/)) { | ||
data.contents = JSON.parse(contents); | ||
} else if (file.path.match(/ya?ml$/)) { | ||
data.contents = require('js-yaml').safeLoad(contents); | ||
} | ||
} catch (err) { | ||
throw new PluginError(PLUGIN_NAME, PLUGIN_NAME + ': error parsing ' + file.path) | ||
throw new PluginError(PLUGIN_NAME, PLUGIN_NAME + ': error parsing ' + file.path); | ||
} | ||
@@ -49,3 +54,5 @@ } | ||
} | ||
return tpl(template, data, options); | ||
data = extend(data, options); | ||
consolidate[options.engine].render(template, data, callback); | ||
} | ||
@@ -70,4 +77,10 @@ | ||
var wait = es.wait(function(err, contents){ | ||
through.write(compile(file, contents, template, data, options)); | ||
through.end(); | ||
compile(file, contents, template, data, options, function(compileErr, output) { | ||
if (compileErr) { | ||
callback(compileErr); | ||
} else { | ||
through.write(output); | ||
through.end(); | ||
} | ||
}); | ||
}); | ||
@@ -77,9 +90,16 @@ | ||
file.contents = through; | ||
callback(null, file); | ||
} else if (gutil.isBuffer(file.contents)) { | ||
compile(file, file.contents.toString('utf-8'), template, data, options, function(compileErr, output) { | ||
if (compileErr) { | ||
callback(compileErr); | ||
} else { | ||
file.contents = new Buffer(output); | ||
callback(null, file); | ||
} | ||
}); | ||
} else { | ||
callback(null, file); | ||
} | ||
if (gutil.isBuffer(file.contents)) { | ||
file.contents = new Buffer(compile(file, file.contents.toString('utf-8'), template, data, options)); | ||
} | ||
callback(null, file); | ||
} | ||
@@ -86,0 +106,0 @@ |
{ | ||
"name": "gulp-wrap", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "A gulp plugin to wrap the stream contents with a lodash template.", | ||
@@ -10,2 +10,3 @@ "keywords": [ | ||
"lodash", | ||
"consolidate", | ||
"gulp" | ||
@@ -29,6 +30,7 @@ ], | ||
"dependencies": { | ||
"consolidate": "^0.10.0", | ||
"event-stream": "*", | ||
"gulp-util": "~3.0.1", | ||
"js-yaml": "^3.2.3", | ||
"lodash.template": "~2.4.1", | ||
"lodash": "~2.4.1", | ||
"node.extend": "~1.1.2" | ||
@@ -35,0 +37,0 @@ }, |
@@ -21,4 +21,4 @@ # gulp-wrap [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] | ||
gulp.src("./src/*.json") | ||
.pipe(wrap('angular.module(\'text\', []).value(<%= contents %>);')) | ||
.pipe(gulp.dest("./dist")); | ||
.pipe(wrap('angular.module(\'text\', []).value(<%= contents %>);')) | ||
.pipe(gulp.dest("./dist")); | ||
``` | ||
@@ -32,4 +32,4 @@ | ||
gulp.src("./src/*.json") | ||
.pipe(wrap({ src: 'path/to/template.txt'})) | ||
.pipe(gulp.dest("./dist")); | ||
.pipe(wrap({ src: 'path/to/template.txt'})) | ||
.pipe(gulp.dest("./dist")); | ||
``` | ||
@@ -43,4 +43,4 @@ | ||
gulp.src("./src/*.json") | ||
.pipe(wrap('Hello, <%= contents.title %>, have a <%= contents.adjective %> day.')) | ||
.pipe(gulp.dest("./dist")); | ||
.pipe(wrap('Hello, <%= contents.title %>, have a <%= contents.adjective %> day.')) | ||
.pipe(gulp.dest("./dist")); | ||
``` | ||
@@ -54,4 +54,4 @@ | ||
gulp.src("./src/*.json") | ||
.pipe(wrap('BEFORE <%= data.contents %> <%= data.someVar %> AFTER', { someVar: 'someVal'}, { variable: 'data' })) | ||
.pipe(gulp.dest("./dist")); | ||
.pipe(wrap('BEFORE <%= data.contents %> <%= data.someVar %> AFTER', { someVar: 'someVal'}, { variable: 'data' })) | ||
.pipe(gulp.dest("./dist")); | ||
``` | ||
@@ -94,2 +94,8 @@ | ||
#### options.engine | ||
Type: `String` | ||
Set the [consolidate template engine](https://www.npmjs.com/package/consolidate) to use. (default to `lodash`). | ||
Using another engine that `lodash` may require installation of additional node package. | ||
## License | ||
@@ -96,0 +102,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8363
86
108
6
+ Addedconsolidate@^0.10.0
+ Addedlodash@~2.4.1
+ Addedconsolidate@0.10.0(transitive)
+ Addedlodash@2.4.2(transitive)
- Removedlodash.template@~2.4.1
- Removedlodash._escapehtmlchar@2.4.1(transitive)
- Removedlodash._escapestringchar@2.4.1(transitive)
- Removedlodash._htmlescapes@2.4.1(transitive)
- Removedlodash._isnative@2.4.1(transitive)
- Removedlodash._objecttypes@2.4.1(transitive)
- Removedlodash._reinterpolate@2.4.1(transitive)
- Removedlodash._reunescapedhtml@2.4.1(transitive)
- Removedlodash._shimkeys@2.4.1(transitive)
- Removedlodash.defaults@2.4.1(transitive)
- Removedlodash.escape@2.4.1(transitive)
- Removedlodash.isobject@2.4.1(transitive)
- Removedlodash.keys@2.4.1(transitive)
- Removedlodash.template@2.4.1(transitive)
- Removedlodash.templatesettings@2.4.1(transitive)
- Removedlodash.values@2.4.1(transitive)