import { Inject , Provide } from '@midwayjs/decorator' ; import { IViewEngine , RenderOptions } from '@midwayjs/view' ; import { NunjucksEnvironment } from './engine' ; @ Provide ( ) export class NunjucksView implements IViewEngine { @ Inject ( ) nunjucks : NunjucksEnvironment ; async render ( name , locals ? , options ? ) { return new Promise ( ( resolve , reject ) => { this . nunjucks . render ( name , locals , ( err , result ) => { if ( err ) return reject ( err ) ; resolve ( result ) ; } ) ; } ) ; } async renderString ( tpl , locals ? , options ? ) { return new Promise ( ( resolve , reject ) => { this . nunjucks . renderString ( tpl , locals , options , ( err , result ) => { if ( err ) return reject ( err ) ; resolve ( result ) ; } ) ; } ) ; } }