New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 4.0.0 to 4.1.0

4

CHANGELOG.md
# Changelog
## v4.1.0
- Add support for the new ejs ([v.2.5.8](https://github.com/mde/ejs/releases/tag/v2.5.8)) async rendering feature. (@Tietew)
## v4.0.0

@@ -4,0 +8,0 @@

@@ -24,7 +24,20 @@ 'use strict'

try {
file.contents = Buffer.from(
ejs.render(file.contents.toString(), ejsData, options)
)
const rendered = ejs.render(file.contents.toString(), ejsData, options)
this.push(file)
if (options.async && typeof rendered.then === 'function') {
rendered.then(rendered => {
file.contents = Buffer.from(rendered)
this.push(file)
}).catch(err => {
this.emit(
'error',
new PluginError(PLUGIN_NAME, err, { fileName: file.path })
)
}).then(callback)
return
}
file.contents = Buffer.from(rendered);
this.push(file);
} catch (err) {

@@ -31,0 +44,0 @@ this.emit(

2

package.json
{
"name": "gulp-ejs",
"version": "4.0.0",
"version": "4.1.0",
"description": "A plugin for Gulp that parses ejs template files",

@@ -5,0 +5,0 @@ "keywords": [

@@ -59,2 +59,24 @@ # gulp-ejs [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]

### Async rendering (requires runtime support)
Since ejs [v2.5.8](https://github.com/mde/ejs/releases/tag/v2.5.8) added support for promise/async-await `renderFile`, you can now use this option with gulp-ejs v4.1.0.
You can use async/await in your ejs templates by passing `{ async: true }` in the ejs options hash:
```javascript
const ejs = require('gulp-ejs')
async function foobar() { /* async task */ }
gulp.src('./templates/*.ejs')
.pipe(ejs({ foobar }, { async: true }))
.pipe(gulp.dest('./dist'))
```
Then in your templates use `await` to call async functions. Here's an example:
```javascript
<%= await foobar() %>
```
## API

@@ -61,0 +83,0 @@

@@ -107,2 +107,35 @@ 'use strict'

})
it('should render async ejs template', function(done) {
/* Skip test if async function is not supported (Node 7.5-) */
try {
/* eslint-disable-next-line no-new-func */
(new Function('return (async function(){}).constructor;'))()
} catch (e) {
if (e instanceof SyntaxError) {
this.skip()
} else {
throw e
}
}
const title = () => new Promise((resolve, reject) => {
process.nextTick(() => resolve('gulp-ejs'))
})
const stream = ejs({ title: title }, { async: true })
stream.on('data', data => {
assert.strictEqual(data.contents.toString(), '<h1>gulp-ejs</h1>')
})
stream.on('end', done)
stream.write(
new Vinyl({
contents: Buffer.from('<h1><%= await title() %></h1>')
})
)
stream.end()
})
})
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