2.2.1 • Published 8 years ago

koa-swig v2.2.1

Weekly downloads
142
License
MIT
Repository
github
Last release
8 years ago

koa-swig

NPM version Build status Test coverage License Dependency status

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

NPM

Usage

  • v2.x

    app.context.render = render(settings);
  • v1.x

    render(app, settings);

Install

npm install koa-swig

Features

  • First, automatically merge ctx.state from koa 0.14.
  • Second, automatically merge ctx.flash.
  • Finally, merge custom locals.

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

  • swig options

    • autoescape
    • cache
    • locals
    • varControls
    • tagControls
    • cmtControls
  • filters: swig custom filters

  • tags: swig custom tags

  • extensions: add extensions for custom tags

  • ext: default view extname

  • root: view root directory

  • writeBody: default(true) auto write body and response

Methods

  • render.swig.setLocals

  • render.swig.getLocals

Others

  • swig-extras A collection of handy tags, filters, and extensions for Swig.

Licences

MIT

2.2.1

8 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.0

10 years ago

1.5.0

10 years ago

1.4.1

10 years ago

1.4.0

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.9.0

10 years ago

0.8.0

10 years ago

0.7.0

10 years ago

0.6.0

10 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.0

11 years ago

0.2.1

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago