Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

egg-view-ejs

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-view-ejs - npm Package Compare versions

Comparing version
1.0.1
to
1.1.0
+6
-0
History.md
1.1.0 / 2017-03-27
==================
* feat: add layout (#6)
* docs: can't overrite default `view` plugin (#5)
1.0.1 / 2017-02-23

@@ -3,0 +9,0 @@ ==================

+14
-3
'use strict';
const ejs = require('ejs');
const RENDER = Symbol('EjsView#_render');

@@ -13,5 +14,3 @@ module.exports = class EjsView {

render(filename, locals, viewOptions) {
const config = Object.assign({}, this.config, viewOptions, { filename });
[RENDER](filename, locals, config) {
return new Promise((resolve, reject) => {

@@ -28,2 +27,14 @@ ejs.renderFile(filename, locals, config, (err, result) => {

* render(filename, locals, viewOptions) {
const config = Object.assign({}, this.config, viewOptions, { filename });
const html = yield this[RENDER](filename, locals, config);
if (!config.layout) {
return html;
}
locals.body = html;
const layout = yield this.app.view.resolve(config.layout);
return yield this[RENDER](layout, locals, config);
}
renderString(tpl, locals, viewOptions) {

@@ -30,0 +41,0 @@ // should disable cache when no filename

+1
-1
{
"name": "egg-view-ejs",
"version": "1.0.1",
"version": "1.1.0",
"description": "egg view plugin for ejs",

@@ -5,0 +5,0 @@ "eggPlugin": {

@@ -35,3 +35,3 @@ # egg-view-ejs

// {app_root}/config/plugin.js
exports.view = {
exports.ejs = {
enable: true,

@@ -54,3 +54,3 @@ package: 'egg-view-ejs',

```
```js
// app/view/hello.ejs

@@ -62,3 +62,3 @@ hello <%= data %>

```
```js
// app/controller/render.js

@@ -80,3 +80,3 @@ exports.ejs = function* () {

```
```html
// app/view/a.ejs include app/view/b.ejs

@@ -88,3 +88,3 @@ <% include b.ejs %>

```
```html
// app/view/home.ejs include app/view/partial/menu.ejs

@@ -94,2 +94,25 @@ <% include /partial/menu.ejs %>

### Layout
You can render a view with layout also:
```js
// app/view/layout.ejs
<%- body%>
// app/controller/render.js
exports.ejs = function* () {
const locals = {
data: 'world',
};
const viewOptions = {
layout: 'layout.ejs'
};
yield ctx.render('hello.ejs', locals, viewOptions);
};
```
## Configuration

@@ -96,0 +119,0 @@