1.0.0 • Published 6 years ago

@totemish/nunjucks-middleware v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Totemish Nunjucks Middleware

This package adds support for Nunjucks in @totemish/framework.

Installation

npm i --save @totemish/framework nunjucks @totemish/nunjucks-middleware

Description

NunjucksMiddleware uses the @totemish templateDirs to get the path to the template file, concatenating it with the controller-specific templateUrl. To learn more about @totemish routing, check here. NunjucksMiddleware accepts all the default Nunjucks options as an argument. E.g. you can provide watch, cache, etc. For more information about Nunjucks options, check here.

Usage

You can enable this middleware globally (preferably as global end middleware as controller result object is unavailable when global start middleware is executed) like so:

import { Server } from '@totemish/framework';
import { NunjucksMiddleware } from '@totemish/nunjucks-middleware';

Server.globalMiddleware.add('end', NunjucksMiddleware());

Alternatively, you can enable it for specific routes by passing it to the array of controller middleware:

import { Controller } from '@totemish/framework';
import { NunjucksMiddleware } from '@totemish/nunjucks-middleware';

@Controller({
  route: '/',
  templateUrl: 'index.njk',
  middleware: [
    NunjucksMiddleware(),
  ]
})
export class IndexController {}

TODO

  • More tests
  • Support for providing custom template files
  • Rendering template strings