koa-modules / swig

Koa view render based on Swig, support tags, filters, and extensions
MIT License
30 stars 12 forks source link

koa-swig

NPM version Build status Test coverage License Dependency status

Koa view render based on Swig, support tags, filters, and extensions.

NPM

Usage

Install

npm install koa-swig

Features

Example

var koa = require('koa');
var render = require('koa-swig');
var app = koa();

app.context.render = render({
  root: path.join(__dirname, 'views'),
  autoescape: true,
  cache: 'memory', // disable, set to false
  ext: 'html',
  locals: locals,
  filters: filters,
  tags: tags,
  extensions: extensions
});

app.use(function *() {
  yield this.render('index');
});

app.listen(2333);
// koa v2.x
var co = require('co');

app.context.render = co.wrap(render({
  // ...your setting
  writeBody: false
}));

app.use(async ctx => ctx.body = await ctx.render('index'));

Settings

Methods

Others

Licences

MIT