think-view-pug
Version:
Pug view adapter for ThinkJS
82 lines (69 loc) • 1.71 kB
Markdown
# think-view-pug
[](https://travis-ci.org/thinkjs/think-view-pug)
[](https://coveralls.io/github/thinkjs/think-view-pug?branch=master)
[](https://www.npmjs.com/package/think-view-pug)
## Install
```
npm install think-view-pug
```
## How to Usage
edit config file `src/config/adapter.js`, add options:
```js
const pug = require('think-view-pug');
exports.view = {
type: 'pug',
common: {
viewPath: path.join(think.ROOT_PATH, 'view'),
extname: '.html',
sep: '_' //seperator between controller and action
},
pug: {
handle: pug,
beforeRender: (pug, handleOptions) => {
// todo
}
}
}
```
### default options
```js
const defaultOptions = {
cache: false,
debug: false
};
```
change options:
```js
exports.view = {
type: 'pug',
pug: {
handle: pug,
options: {
cache: true,
self: true
},
beforeRender: (pug, handleOptions) => {
// todo
}
}
}
```
you can find all pug support options at https://pugjs.org/api/reference.html
### beforeRender
you can use `beforeRender` method to enhance pug:
```js
exports.view = {
type: 'pug',
pug: {
handle: pug,
beforeRender: (pug, handleOptions) => {
pug.filters['my-own-filter'] = (text, options) => {
if (options.addStart) text = 'Start\n' + text;
if (options.addEnd) text = text + '\nEnd';
return text;
};
}
}
}
```
you can find all APIs at https://pugjs.org/api/reference.html