Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-ejs

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-ejs - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

test/expected/config.js.fixture

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`

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc