Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to next release v5.0.0 #61

Merged
merged 12 commits into from
Jul 9, 2022
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "standard",
"env": {
"mocha": true
}
}
31 changes: 17 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp
# OS #
###################
.DS_Store
.idea
Thumbs.db
tmp
temp

pids
logs
results

package-lock.json
npm-debug.log
# Node.js #
###################
node_modules
package-lock.json
yarn.lock


# NYC #
###################
coverage
.nyc_output
14 changes: 14 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"all": false,
"exclude": [
"**/*.test.js",
"example"
],
"reporter": [
"text-lcov",
"text",
"lcov"
],
"report-dir": "./coverage",
"temp-dir": "./.nyc_output"
}
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: node_js
node_js:
- '7.6.0'
script: make test
- 12
- 14
- 16
script:
- npm run ci
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2017 dead_horse
Copyright(c) 2017 dead_horse
Copyright(c) 2021-2022 3imed-jaberi <imed-jaberi@outlook.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
koa-ejs
=========
# koa-ejs

[![Build Status](https://secure.travis-ci.org/koajs/ejs.svg)](http://travis-ci.org/koajs/ejs)
> Koa ejs view render middleware. support all feature of [ejs](https://github.com/mde/ejs).

Koa ejs view render middleware. support all feature of [ejs](https://github.com/mde/ejs).
[![Build Status](https://secure.travis-ci.org/koajs/ejs.svg)](http://travis-ci.org/koajs/ejs)

[![NPM](https://nodei.co/npm/koa-ejs.png?downloads=true)](https://nodei.co/npm/koa-ejs/)

Expand All @@ -12,38 +11,39 @@ Koa ejs view render middleware. support all feature of [ejs](https://github.com/
### Example

```js
const Koa = require('koa');
const render = require('koa-ejs');
const path = require('path');
const Koa = require("koa");
const render = require("koa-ejs");
const path = require("path");

const app = new Koa();
render(app, {
root: path.join(__dirname, 'view'),
layout: 'template',
viewExt: 'html',
root: path.join(__dirname, "view"),
layout: "template",
viewExt: "html",
cache: false,
debug: true
debug: true,
});

app.use(async function (ctx) {
await ctx.render('user');
await ctx.render("user");
});

app.listen(7001);
```

Or you can checkout the [example](https://github.com/koajs/ejs/tree/master/example).

### settings
### Settings

* root: view root directory.
* layout: global layout file, default is `layout`, set `false` to disable layout.
* viewExt: view file extension (default `html`).
* cache: cache compiled templates (default `true`).
* debug: debug flag (default `false`).
* delimiter: character to use with angle brackets for open / close (default `%`).
* async: When true, EJS will use an async function for rendering. Depends on async/await support in the JS runtime.
* outputFunctionName: Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags.
- root: view root directory.
- fs: file system module with same Node.js fs interface (default `Node.js fs module`).
- layout: global layout file, default is `layout`, set `false` to disable layout.
- viewExt: view file extension (default `html`).
- cache: cache compiled templates (default `true`).
- debug: debug flag (default `false`).
- delimiter: character to use with angle brackets for open / close (default `%`).
- async: When true, EJS will use an async function for rendering. Depends on async/await support in the JS runtime.
- outputFunctionName: Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags.

### Layouts

Expand All @@ -68,21 +68,19 @@ Supports ejs includes.

```
<div>
<% include user.html %>
<%- include ('user.html') -%>
</div>
```

### State

Support [`ctx.state` in koa](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate).

## Licences
(The MIT License)

Copyright (c) 2017 dead-horse and other contributors
### TypeScript

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
If you're project based on TypeScript, we recommend using [`@types/koa-ejs`](https://www.npmjs.com/package/@types/koa-ejs) until we start supporting it in the upcoming releases.

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
## Licences

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[(The MIT License)](LICENSE)
51 changes: 51 additions & 0 deletions example/app-with-custom-fs-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*!
* koa-ejs - example/app-with-custom-fs-module
*
* Copyright(c) 2022 3imed-jaberi <imed-jaberi@outlook.com>
* MIT Licensed
*/

'use strict'

/**
* Module dependencies.
*/

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

const app = new Koa()

render(app, {
root: path.join(__dirname, 'view'),
fs: require('mz/fs'),
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()
})
.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()
} else {
app.listen(7001)
console.log('open http://localhost:7001')
}

app.on('error', function (err) {
console.log(err.stack)
})
53 changes: 26 additions & 27 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
/*!
* koa-ejs - example/app.js
*
* Copyright(c) 2017 dead_horse <dead_horse@qq.com>
* 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>
Loading