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 3.3.0 to 4.0.0

.npmignore

42

index.js
'use strict'
var through = require('through2')
var PluginError = require('plugin-error')
var replaceExtension = require('replace-ext')
var ejs = require('ejs')
const through = require('through2')
const PluginError = require('plugin-error')
const ejs = require('ejs')
var gulpEjs = function(data, options, settings) {
data = data || {}
options = options || {}
settings = settings || {}
const PLUGIN_NAME = 'gulp-ejs'
return through.obj(function(file, enc, cb) {
function render(data, options = {}) {
return through.obj(function(file, encoding, callback) {
if (file.isNull()) {
this.push(file)
return cb()
return callback(null, file)
}
if (file.isStream()) {
this.emit('error', new PluginError('gulp-ejs', 'Streaming not supported'))
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'))
}
var fileData = Object.assign({}, data, file.data)
options.filename = file.path
const ejsData = Object.assign({}, data, file.data)
try {
file.contents = Buffer.from(
ejs.render(file.contents.toString(), fileData, options)
ejs.render(file.contents.toString(), ejsData, options)
)
if (typeof settings.ext !== 'undefined') {
file.path = replaceExtension(file.path, settings.ext)
}
this.push(file)
} catch (err) {
this.emit('error', new PluginError('gulp-ejs', err.toString()))
this.emit(
'error',
new PluginError(PLUGIN_NAME, err, { fileName: file.path })
)
}
this.push(file)
cb()
callback()
})
}
gulpEjs.ejs = ejs
// expose ejs object for configuration
render.__EJS__ = ejs
module.exports = gulpEjs
module.exports = render
{
"name": "gulp-ejs",
"version": "3.3.0",
"version": "4.0.0",
"description": "A plugin for Gulp that parses ejs template files",

@@ -23,5 +23,6 @@ "keywords": [

"scripts": {
"lint": "eslint test index.js",
"lint": "eslint **/*.js",
"lint:fix": "prettier --write index.js test/**/*.js",
"test": "npm run lint && mocha"
"pretest": "npm run lint",
"test": "mocha"
},

@@ -31,20 +32,19 @@ "dependencies": {

"plugin-error": "^1.0.0",
"replace-ext": "^1.0.0",
"through2": "^3.0.0"
"through2": "^3.0.1"
},
"devDependencies": {
"eslint": "^5.9.0",
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-import": "^2.17.1",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"mocha": "5.2.0",
"prettier": "^1.15.2",
"should": "13.2.3",
"gulp-data": "^1.3.1",
"mocha": "^6.1.3",
"prettier": "^1.17.0",
"vinyl": "^2.2.0"
},
"engines": {
"node": ">= 4",
"npm": ">=1.2.10"
"node": ">= 6",
"npm": ">= 3"
},

@@ -51,0 +51,0 @@ "licenses": [

@@ -26,3 +26,7 @@ # 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`.
### Watch mode error handling (for gulp v3 or below)
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` or an ejs syntax error.
Here's an example on how to make it work:

@@ -42,25 +46,19 @@

If you want to specify the extension of output files, set the ext option:
**Please note that you don't need to do this for Gulp v4.**
```javascript
var ejs = require('gulp-ejs')
### Accessing the ejs object
gulp.src('./templates/*.ejs')
.pipe(ejs({ msg: 'Hello Gulp!'}, {}, { ext: '.html' }))
.pipe(gulp.dest('./dist'))
```
### Acessing the ejs object
The ejs object is also exported and you can use it to configure ejs:
```javascript
var gulpEjs = require('gulp-ejs')
const ejs = require('gulp-ejs')
gulpEjs.ejs.fileLoader = function () { /* custom file loader */ }
ejs.__EJS__.fileLoader = function () { /* custom file loader */ }
```
**Note:** As of version 4, the exported ejs object was renamed from `ejs` to `__EJS__`.
## API
### ejs(data, options, settings)
### ejs(data, options)

@@ -83,17 +81,18 @@ #### data

#### settings
Type: `hash`
Default: `{}`
### Renaming file extensions
A hash object to configure the plugin.
As of version 4, the third api parameter `settings` was removed. You can no longer provide an extension. This is because it falls out of the scope of `gulp-ejs`. So if you need to save the file with a different extension you can use [gulp-rename](https://npmjs.com/package/gulp-rename).
##### settings.ext
Type: `String`
Default: `undefined`
Here's an example for template files with `.ejs` extension that are rendered into `.html` files:
Defines the file extension that will be appended to the filename. If no extension is provided, the same extension of the input file will be used.
```javascript
const ejs = require('gulp-ejs')
const rename = require('gulp-rename')
**Note:** As of `v2.0.0` the output file extension is no longer `.html` by default, you need to specify it, otherwise it will have the same extension of the input file.
gulp.src('./templates/*.ejs')
.pipe(ejs({ title: 'gulp-ejs' }))
.pipe(rename({ extname: '.html' }))
.pipe(gulp.dest('./dist'))
```
## License

@@ -100,0 +99,0 @@

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