Comparing version 2.3.0 to 3.0.0
71
index.js
@@ -1,43 +0,44 @@ | ||
'use strict'; | ||
'use strict' | ||
var through = require('through2'); | ||
var gutil = require('gulp-util'); | ||
var ejs = require('ejs'); | ||
var assign = require('object-assign'); | ||
var through = require('through2') | ||
var gutil = require('gulp-util') | ||
var ejs = require('ejs') | ||
var assign = require('object-assign') | ||
module.exports = function (options, settings) { | ||
options = options || {}; | ||
settings = settings || {}; | ||
module.exports = function (data, options, settings) { | ||
data = data || {} | ||
options = options || {} | ||
settings = settings || {} | ||
return through.obj(function (file, enc, cb) { | ||
if (file.isNull()) { | ||
this.push(file); | ||
return 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') | ||
); | ||
} | ||
if (file.isStream()) { | ||
this.emit( | ||
'error', | ||
new gutil.PluginError('gulp-ejs', 'Streaming not supported') | ||
) | ||
} | ||
options = assign({}, options, file.data); | ||
options.filename = file.path; | ||
data = assign({}, data, file.data) | ||
options.filename = file.path | ||
try { | ||
file.contents = new Buffer( | ||
ejs.render(file.contents.toString(), options) | ||
); | ||
try { | ||
file.contents = new Buffer( | ||
ejs.render(file.contents.toString(), data, options) | ||
) | ||
if (typeof settings.ext !== 'undefined') { | ||
file.path = gutil.replaceExtension(file.path, settings.ext); | ||
} | ||
} catch (err) { | ||
this.emit('error', new gutil.PluginError('gulp-ejs', err.toString())); | ||
} | ||
if (typeof settings.ext !== 'undefined') { | ||
file.path = gutil.replaceExtension(file.path, settings.ext) | ||
} | ||
} catch (err) { | ||
this.emit('error', new gutil.PluginError('gulp-ejs', err.toString())) | ||
} | ||
this.push(file); | ||
cb(); | ||
}); | ||
}; | ||
this.push(file) | ||
cb() | ||
}) | ||
} |
{ | ||
"name": "gulp-ejs", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "A plugin for Gulp that parses ejs template files", | ||
@@ -23,2 +23,3 @@ "keywords": [ | ||
"scripts": { | ||
"pretest": "standard", | ||
"test": "mocha" | ||
@@ -28,3 +29,3 @@ }, | ||
"ejs": "2.5.5", | ||
"gulp-util": "3.0.7", | ||
"gulp-util": "3.0.8", | ||
"object-assign": "^4.1.0", | ||
@@ -35,3 +36,4 @@ "through2": "2.0.3" | ||
"mocha": "3.1.2", | ||
"should": "11.1.2" | ||
"should": "11.2.0", | ||
"standard": "^8.6.0" | ||
}, | ||
@@ -38,0 +40,0 @@ "engines": { |
@@ -16,3 +16,3 @@ # gulp-ejs [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] | ||
```javascript | ||
var ejs = require("gulp-ejs"); | ||
var ejs = require("gulp-ejs") | ||
@@ -23,3 +23,3 @@ gulp.src("./templates/*.ejs") | ||
})) | ||
.pipe(gulp.dest("./dist")); | ||
.pipe(gulp.dest("./dist")) | ||
``` | ||
@@ -30,4 +30,4 @@ 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`. | ||
```javascript | ||
var ejs = require('gulp-ejs'); | ||
var gutil = require('gulp-util'); | ||
var ejs = require('gulp-ejs') | ||
var gutil = require('gulp-util') | ||
@@ -38,3 +38,3 @@ gulp.src('./templates/*.ejs') | ||
}).on('error', gutil.log)) | ||
.pipe(gulp.dest('./dist')); | ||
.pipe(gulp.dest('./dist')) | ||
``` | ||
@@ -45,4 +45,12 @@ This will make gulp log the error and continue normal execution. | ||
### ejs(options, settings) | ||
### ejs(data, options, settings) | ||
#### data | ||
Type: `hash` | ||
Default: `{}` | ||
A hash object where each key corresponds to a variable in your template. | ||
**Note:** As of `v1.2.0`, `file.data` is supported as a way of passing data into ejs. See [this](https://github.com/colynb/gulp-data#note-to-gulp-plugin-authors). If both `file.data` and `data` are passed, they are merged (`data` works as default for ejs options and `file.data` overrides it.) | ||
#### options | ||
@@ -52,8 +60,6 @@ Type: `hash` | ||
A hash object where each key corresponds to a variable in your template. Also you can set ejs options in this hash. | ||
A hash object for ejs options. | ||
For more info on `ejs` options, check the [project's documentation](https://github.com/mde/ejs). | ||
**Note:** As of `v1.2.0`, `file.data` is supported as a way of passing data into ejs. See [this](https://github.com/colynb/gulp-data#note-to-gulp-plugin-authors). If both `file.data` and `options` are passed, they are merged (`options` works as default for ejs options and `file.data` overrides it.) | ||
#### settings | ||
@@ -60,0 +66,0 @@ Type: `hash` |
357
test/main.js
@@ -1,81 +0,76 @@ | ||
/*global describe, it*/ | ||
'use strict'; | ||
/* global describe, it */ | ||
'use strict' | ||
var fs = require('fs'), | ||
should = require('should'), | ||
path = require('path'); | ||
require('mocha'); | ||
var fs = require('fs') | ||
var should = require('should') | ||
var path = require('path') | ||
require('mocha') | ||
var gutil = require('gulp-util'), | ||
ejs = require('../'); | ||
var gutil = require('gulp-util') | ||
var ejs = require('../') | ||
describe('gulp-ejs', function () { | ||
var expectedFile = new gutil.File({ | ||
path: 'test/expected/output.html', | ||
cwd: 'test/', | ||
base: 'test/expected', | ||
contents: fs.readFileSync('test/expected/output.html') | ||
}) | ||
var expectedFile = new gutil.File({ | ||
path: 'test/expected/output.html', | ||
cwd: 'test/', | ||
base: 'test/expected', | ||
contents: fs.readFileSync('test/expected/output.html') | ||
}); | ||
var expectedFileWithPartial = new gutil.File({ | ||
path: 'test/expected/outputWithPartial.html', | ||
cwd: 'test/', | ||
base: 'test/expected', | ||
contents: fs.readFileSync('test/expected/outputWithPartial.html') | ||
}) | ||
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) { | ||
var srcFile = new gutil.File({ | ||
path: 'test/fixtures/ok.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/ok.ejs') | ||
}) | ||
it('should produce correct html output when rendering a file', function (done) { | ||
var stream = ejs({ title: 'gulp-ejs' }) | ||
var srcFile = new gutil.File({ | ||
path: 'test/fixtures/ok.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/ok.ejs') | ||
}); | ||
stream.on('error', function (err) { | ||
should.exist(err) | ||
done(err) | ||
}) | ||
var stream = ejs({ title: 'gulp-ejs' }); | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
stream.on('error', function (err) { | ||
should.exist(err); | ||
done(err); | ||
}); | ||
String(newFile.contents).should.equal(String(expectedFile.contents)) | ||
done() | ||
}) | ||
stream.on('data', function (newFile) { | ||
stream.write(srcFile) | ||
String(path.extname(srcFile.path)).should.equal('.ejs') | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
stream.end() | ||
}) | ||
String(newFile.contents).should.equal(String(expectedFile.contents)); | ||
done(); | ||
}); | ||
it('should throw error when syntax is incorrect', function (done) { | ||
var srcFile = new gutil.File({ | ||
path: 'test/fixtures/nok.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/nok.ejs') | ||
}) | ||
stream.write(srcFile); | ||
String(path.extname(srcFile.path)).should.equal('.ejs'); | ||
var stream = ejs({ title: 'gulp-ejs' }) | ||
stream.end(); | ||
}); | ||
stream.on('error', function (err) { | ||
should.exist(err) | ||
done() | ||
}) | ||
it('should throw error when syntax is incorrect', function (done) { | ||
stream.write(srcFile) | ||
stream.end() | ||
}) | ||
var srcFile = new gutil.File({ | ||
path: 'test/fixtures/nok.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/nok.ejs') | ||
}); | ||
var stream = ejs({ title: 'gulp-ejs' }); | ||
stream.on('error', function (err) { | ||
should.exist(err); | ||
done(); | ||
}); | ||
stream.write(srcFile); | ||
stream.end(); | ||
}); | ||
it('should produce correct html output with a specific file extension', function (done) { | ||
var srcFile = new gutil.File({ | ||
@@ -86,28 +81,26 @@ path: 'test/fixtures/ok.ejs', | ||
contents: fs.readFileSync('test/fixtures/ok.ejs') | ||
}); | ||
}) | ||
var stream = ejs({ title: 'gulp-ejs' }, {ext:'.txt'}); | ||
var stream = ejs({ title: 'gulp-ejs' }, {}, { ext: '.txt' }) | ||
stream.on('error', function (err) { | ||
should.exist(err); | ||
done(err); | ||
}); | ||
should.exist(err) | ||
done(err) | ||
}) | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(String(expectedFile.contents)) | ||
done() | ||
}) | ||
String(newFile.contents).should.equal(String(expectedFile.contents)); | ||
done(); | ||
}); | ||
stream.write(srcFile) | ||
String(path.extname(srcFile.path)).should.equal('.txt') | ||
stream.write(srcFile); | ||
String(path.extname(srcFile.path)).should.equal('.txt'); | ||
stream.end() | ||
}) | ||
stream.end(); | ||
}); | ||
it('should produce correct html output using partial', function (done) { | ||
var srcFile = new gutil.File({ | ||
@@ -118,107 +111,79 @@ path: 'test/fixtures/withpartial.ejs', | ||
contents: fs.readFileSync('test/fixtures/withpartial.ejs') | ||
}); | ||
}) | ||
var stream = ejs({ title: 'gulp-ejs', msg: 'gulp-ejs', name: 'rpvl' }); | ||
var stream = ejs({ title: 'gulp-ejs', msg: 'gulp-ejs', name: 'rpvl' }) | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(String(expectedFileWithPartial.contents)) | ||
done() | ||
}) | ||
String(newFile.contents).should.equal(String(expectedFileWithPartial.contents)); | ||
done(); | ||
}); | ||
stream.write(srcFile) | ||
stream.end() | ||
}) | ||
stream.write(srcFile); | ||
stream.end(); | ||
}); | ||
it('should support passing data with gulp-data', function (done) { | ||
var srcFile = new gutil.File({ | ||
path: 'test/fixtures/ok.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/ok.ejs') | ||
}) | ||
it('should provide correct filenames', function (done) { | ||
// simulate gulp-data plugin | ||
srcFile.data = { title: 'gulp-ejs' } | ||
var file1 = new gutil.File({ | ||
path: 'foo.html', | ||
contents: new Buffer('<%- filename -%>') | ||
}); | ||
var stream = ejs() | ||
var file2 = new gutil.File({ | ||
path: 'bar.html', | ||
contents: new Buffer('<%- filename -%>') | ||
}); | ||
stream.on('error', function (err) { | ||
should.exist(err) | ||
done(err) | ||
}) | ||
var stream = ejs(); | ||
stream.on('data', function (newFile) { | ||
newFile.contents.toString().should.equal(newFile.path); | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
if (newFile.path == 'bar.html') { | ||
done(); | ||
} | ||
}); | ||
String(newFile.contents).should.equal(String(expectedFile.contents)) | ||
done() | ||
}) | ||
stream.write(file1); | ||
stream.write(file2); | ||
stream.end(); | ||
}); | ||
stream.write(srcFile) | ||
String(path.extname(srcFile.path)).should.equal('.ejs') | ||
it('should support passing data with gulp-data', function (done) { | ||
var srcFile = new gutil.File({ path: 'test/fixtures/ok.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/ok.ejs') | ||
}); | ||
stream.end() | ||
}) | ||
// simulate gulp-data plugin | ||
srcFile.data = { title: 'gulp-ejs' }; | ||
var stream = ejs(); | ||
stream.on('error', function (err) { | ||
should.exist(err); | ||
done(err); | ||
}); | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(String(expectedFile.contents)); | ||
done(); | ||
}); | ||
stream.write(srcFile); | ||
String(path.extname(srcFile.path)).should.equal('.ejs'); | ||
stream.end(); | ||
}); | ||
it('should merge options and file.data when both are passed', 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 srcFile = new gutil.File({ | ||
path: 'test/fixtures/withpartial.ejs', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/withpartial.ejs') | ||
}) | ||
// simulate gulp-data plugin | ||
srcFile.data = { name: 'rpvl' }; | ||
// simulate gulp-data plugin | ||
srcFile.data = { name: 'rpvl' } | ||
var stream = ejs({ msg: 'gulp-ejs', name: 'foo' }); | ||
var stream = ejs({ msg: 'gulp-ejs', name: 'foo' }) | ||
stream.on('error', function (err) { | ||
should.exist(err); | ||
done(err); | ||
}); | ||
stream.on('error', function (err) { | ||
should.exist(err) | ||
done(err) | ||
}) | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
String(newFile.contents).should.equal(String(expectedFileWithPartial.contents)); | ||
done(); | ||
}); | ||
String(newFile.contents).should.equal(String(expectedFileWithPartial.contents)) | ||
done() | ||
}) | ||
stream.write(srcFile); | ||
stream.end(); | ||
}); | ||
stream.write(srcFile) | ||
stream.end() | ||
}) | ||
@@ -232,27 +197,28 @@ describe('with assets', function () { | ||
contents: fs.readFileSync('test/fixtures/config.js.ejs') | ||
}); | ||
}) | ||
var stream = ejs({ | ||
baseUrl: 'https://github.com/rogeriopvl/gulp-ejs', | ||
FacebookApiToken: function () { | ||
return '0e24aa7fa3d7acffdb2085cec5ab0ce704f48318'; | ||
} | ||
}, { | ||
ext: ''// remove .ejs extension | ||
}); | ||
var stream = ejs( | ||
{ | ||
baseUrl: 'https://github.com/rogeriopvl/gulp-ejs', | ||
FacebookApiToken: function () { | ||
return '0e24aa7fa3d7acffdb2085cec5ab0ce704f48318' | ||
} | ||
}, | ||
{}, | ||
{ ext: '' } // remove .ejs extension | ||
) | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
path.extname(newFile.path).should.equal('.js') | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
path.extname(newFile.path).should.equal('.js'); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/config.js.fixture', 'utf8')) | ||
done() | ||
}) | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/config.js', 'utf8')); | ||
done(); | ||
}); | ||
stream.write(srcFile) | ||
stream.end() | ||
}) | ||
stream.write(srcFile); | ||
stream.end(); | ||
}); | ||
it('should templating with stylesheets', function (done) { | ||
@@ -264,26 +230,25 @@ var srcFile = new gutil.File({ | ||
contents: fs.readFileSync('test/fixtures/head.css.ejs') | ||
}); | ||
}) | ||
var stream = ejs({ | ||
fonts_path: function () { | ||
return '../fonts/fontawesome-webfont.eot?v=4.1.0'; | ||
return '../fonts/fontawesome-webfont.eot?v=4.1.0' | ||
} | ||
}, { | ||
}, {}, { | ||
ext: ''// remove .ejs extension | ||
}); | ||
}) | ||
stream.on('data', function (newFile) { | ||
should.exist(newFile) | ||
should.exist(newFile.contents) | ||
path.extname(newFile.path).should.equal('.css') | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
path.extname(newFile.path).should.equal('.css'); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/head.css', 'utf8')) | ||
done() | ||
}) | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/head.css', 'utf8')); | ||
done(); | ||
}); | ||
stream.write(srcFile); | ||
stream.end(); | ||
}); | ||
}); | ||
}); | ||
stream.write(srcFile) | ||
stream.end() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
86
14465
3
241
1
+ Addeddateformat@2.2.0(transitive)
+ Addedgulp-util@3.0.8(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddateformat@1.0.12(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedgulp-util@3.0.7(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
Updatedgulp-util@3.0.8