Skip to content

Commit

Permalink
update the example with ejs-v3 spec 🍾 ..
Browse files Browse the repository at this point in the history
  • Loading branch information
3imed-jaberi committed Jul 13, 2021
1 parent 96f25c5 commit 16f01fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
52 changes: 25 additions & 27 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,46 @@
* MIT Licensed
*/

'use strict';
'use strict'

/**
* Module dependencies.
*/

const Koa = require('koa');
const render = require('..');
const path = require('path');
const Koa = require('koa')
const render = require('..')
const path = require('path')

const app = new Koa();
const app = new Koa()

render(app, {
root: path.join(__dirname, 'view'),
layout: 'template',
viewExt: 'html',
cache: false,
debug: false,
});

app.use(function (ctx, next) {
ctx.state = ctx.state || {};
ctx.state.now = new Date();
ctx.state.ip = ctx.ip;
ctx.state.version = '2.0.0';
return next();
});

app.use(async function (ctx) {
const users = [{ name: 'Dead Horse' }, { name: 'Jack' }, { name: 'Tom' }];
await ctx.render('content', {
users
});
});
debug: false
})

app
.use(function (ctx, next) {
ctx.state = ctx.state || {}
ctx.state.now = new Date()
ctx.state.ip = ctx.ip
ctx.state.version = '2.0.0'
return next()
})
.use(async function (ctx) {
const users = [{ name: 'Dead Horse' }, { name: 'Imed Jaberi' }, { name: 'Tom' }]
await ctx.render('content', { users })
})

if (process.env.NODE_ENV === 'test') {
module.exports = app.callback();
module.exports = app.callback()
} else {
app.listen(7001);
console.log('open http://localhost:7001');
app.listen(7001)
console.log('open http://localhost:7001')
}

app.on('error', function (err) {
console.log(err.stack);
});
console.log(err.stack)
})
2 changes: 1 addition & 1 deletion example/view/content.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<p>request ip is: <%= ip %></p>
<% include user.html %>
<%- include('user.html') -%>
</div>
2 changes: 1 addition & 1 deletion example/view/content.noext.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<p>request ip is: <%= ip %></p>
<% include user %>
<%- include ('user') -%>
</div>

0 comments on commit 16f01fa

Please sign in to comment.