# koa-swig

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

Latest version **2.2.1** (published 2016-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-swig
pnpm add koa-swig
yarn add koa-swig
bun add koa-swig
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2016-12-17 |
| First published | 2014-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 30 |
| Author | fundon |
| Maintainers | fundon |
| Keywords | koa, render, view, swig, locals, flash |

## Links

- npm: https://www.npmjs.com/package/koa-swig
- Repository: https://github.com/koa-modules/swig
- Homepage: https://github.com/koa-modules/swig#readme
- Issues: https://github.com/koa-modules/swig/issues
- npm.io page: https://npm.io/package/koa-swig

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^2.x
- [thenify](https://npm.io/package/thenify.md) ^3.1.0
- [utils-merge](https://npm.io/package/utils-merge.md) ^1.0.0
- [swig-templates](https://npm.io/package/swig-templates.md) ^2.0.2

## Recent versions

- 2.2.1 (latest) — 2016-12-17
- 2.2.0 — 2016-03-23
- 2.1.0 — 2015-10-14
- 2.0.0 — 2015-04-10
- 1.5.0 — 2015-04-10
- 1.4.1 — 2015-04-10
- 1.4.0 — 2015-04-08
- 1.3.0 — 2015-03-06
- 1.2.0 — 2014-12-18
- 1.1.0 — 2014-12-11
- 1.0.0 — 2014-11-14
- 0.9.0 — 2014-10-05
- 0.8.0 — 2014-09-22
- 0.7.0 — 2014-08-20
- 0.6.0 — 2014-08-20
- … 10 more at https://npm.io/package/koa-swig/versions

## README

# koa-swig

[![NPM version][npm-img]][npm-url]
[![Build status][travis-img]][travis-url]
[![Test coverage][coveralls-img]][coveralls-url]
[![License][license-img]][license-url]
[![Dependency status][david-img]][david-url]

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

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

### Usage

* **v2.x**

    ```js
    app.context.render = render(settings);
    ```

* **v1.x**

    ```js
    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

```js
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);
```

```js
// 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](http://paularmstrong.github.io/swig/docs/api/#SwigOpts)
  - autoescape
  - cache
  - locals
  - varControls
  - tagControls
  - cmtControls

* filters: swig custom [filters](http://paularmstrong.github.io/swig/docs/extending/#filters)

* tags: swig custom [tags](http://paularmstrong.github.io/swig/docs/extending/#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](https://github.com/paularmstrong/swig-extras) A collection of handy tags, filters, and extensions for Swig.

### Licences

MIT

[koa]: http://koajs.com
[swig]: http://paularmstrong.github.io/swig/

[npm-img]: https://img.shields.io/npm/v/koa-swig.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-swig
[travis-img]: https://img.shields.io/travis/koa-modules/swig.svg?style=flat-square
[travis-url]: https://travis-ci.org/koa-modules/swig
[coveralls-img]: https://img.shields.io/coveralls/koa-modules/swig.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/koa-modules/swig?branch=master
[license-img]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
[license-url]: LICENSE
[david-img]: https://img.shields.io/david/koa-modules/swig.svg?style=flat-square
[david-url]: https://david-dm.org/koa-modules/swig

---
_Source: https://npm.io/package/koa-swig · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
