Comparing version 0.1.5 to 0.2.0
24
index.js
'use strict'; | ||
var es = require('event-stream'); | ||
var through = require('through2'); | ||
var gutil = require('gulp-util'); | ||
@@ -12,12 +12,26 @@ var ejs = require('ejs'); | ||
return es.map(function (file, cb) { | ||
return through.obj(function (file, enc, cb) { | ||
if (file.isNull()) { | ||
this.push(file); | ||
return cb(); | ||
} | ||
if (file.isStream()) { | ||
this.emit( | ||
'error', | ||
new gutil.PluginError('gulp-ejs', 'Streaming not supported') | ||
); | ||
} | ||
options.filename = options.filename || file.path; | ||
try { | ||
options.filename = options.filename || file.path; | ||
file.contents = new Buffer(ejs.render(file.contents.toString(), options)); | ||
file.path = gutil.replaceExtension(file.path, settings.ext); | ||
} catch (err) { | ||
return cb(new gutil.PluginError('gulp-ejs', err)); | ||
this.emit('error', new gutil.PluginError('gulp-ejs', err.toString())); | ||
} | ||
cb(null, file); | ||
this.push(file); | ||
cb(); | ||
}); | ||
}; |
{ | ||
"name": "gulp-ejs", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "A plugin for Gulp that parses ejs template files", | ||
@@ -26,9 +26,9 @@ "keywords": [ | ||
"dependencies": { | ||
"event-stream": "*", | ||
"gulp-util": "~2.2.6", | ||
"ejs": "~0.8.5" | ||
"gulp-util": "^2.2.14", | ||
"ejs": "^0.8.5", | ||
"through2": "^0.4.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.14.0", | ||
"should": "~2.1.0" | ||
"should": "^2.1.1", | ||
"mocha": "^1.14.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "engines": { |
@@ -24,3 +24,17 @@ # gulp-ejs [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] | ||
``` | ||
If you want to use `gulp-ejs` in a watch/livereload task, you may want to avoid gulp exiting on error when, for instance, a partial file is `ENOENT`. | ||
Here's an example on how to make it work: | ||
```javascript | ||
var ejs = require('gulp-ejs'); | ||
var gutil = require('gulp-util'); | ||
gulp.src('./templates/*.ejs') | ||
.pipe(ejs({ | ||
msg: 'Hello Gulp!' | ||
}).on('error', gutil.log)) | ||
.pipe(gulp.dest('./dist')); | ||
``` | ||
This will make gulp log the error and continue normal execution. | ||
## API | ||
@@ -27,0 +41,0 @@ |
@@ -21,2 +21,9 @@ /*global describe, it*/ | ||
var expectedFileWithPartial = new gutil.File({ | ||
path: 'test/expected/outputWithPartial.html', | ||
cwd: 'test/', | ||
base: 'test/expected', | ||
contents: fs.readFileSync('test/expected/outputWithPartial.html') | ||
}); | ||
it('should produce correct html output when rendering a file', function (done) { | ||
@@ -103,2 +110,27 @@ | ||
}); | ||
it('should produce correct html output using partial', function (done) { | ||
var srcFile = new gutil.File({ | ||
path: 'test/fixtures/withpartial.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/withpartial.ejs') | ||
}); | ||
var stream = ejs({ title: 'gulp-ejs', msg: 'gulp-ejs', name: 'rpvl' }); | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(String(expectedFileWithPartial.contents)); | ||
done(); | ||
}); | ||
stream.write(srcFile); | ||
stream.end(); | ||
}); | ||
}); |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
9649
16
128
0
76
+ Addedthrough2@^0.4.1
+ Addedobject-keys@0.4.0(transitive)
+ Addedthrough2@0.4.2(transitive)
+ Addedxtend@2.1.2(transitive)
- Removedevent-stream@*
- Removedduplexer@0.1.2(transitive)
- Removedevent-stream@4.0.1(transitive)
- Removedfrom@0.1.7(transitive)
- Removedmap-stream@0.0.7(transitive)
- Removedpause-stream@0.0.11(transitive)
- Removedsplit@1.0.1(transitive)
- Removedstream-combiner@0.2.2(transitive)
- Removedthrough@2.3.8(transitive)
Updatedejs@^0.8.5
Updatedgulp-util@^2.2.14