• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

koa-modules/swig: Koa view render based on Swig, support tags, filters, and exte ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

koa-modules/swig

开源软件地址:

https://github.com/koa-modules/swig

开源编程语言:

JavaScript 95.7%

开源软件介绍:

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap