@fastify/view
Advanced tools
Comparing version 7.3.0 to 7.4.0
16
index.js
@@ -53,2 +53,13 @@ 'use strict' | ||
function setupNunjucksEnv (_engine) { | ||
if (type === 'nunjucks') { | ||
const env = _engine.configure(templatesDir, globalOptions) | ||
if (typeof globalOptions.onConfigure === 'function') { | ||
globalOptions.onConfigure(env) | ||
} | ||
return env | ||
} | ||
return null | ||
} | ||
try { | ||
@@ -66,3 +77,3 @@ templatesDirIsValid(templatesDir) | ||
const dotRender = type === 'dot' ? viewDot.call(fastify, preProcessDot.call(fastify, templatesDir, globalOptions)) : null | ||
const nunjucksEnv = type === 'nunjucks' ? engine.configure(templatesDir, globalOptions) : null | ||
const nunjucksEnv = setupNunjucksEnv(engine) | ||
@@ -450,5 +461,2 @@ const renders = { | ||
} | ||
if (typeof globalOptions.onConfigure === 'function') { | ||
globalOptions.onConfigure(nunjucksEnv) | ||
} | ||
data = Object.assign({}, defaultCtx, this.locals, data) | ||
@@ -455,0 +463,0 @@ // Append view extension. |
{ | ||
"name": "@fastify/view", | ||
"version": "7.3.0", | ||
"version": "7.4.0", | ||
"description": "Template plugin for Fastify", | ||
@@ -56,3 +56,3 @@ "main": "index.js", | ||
"html-minifier": "^4.0.0", | ||
"liquidjs": "^9.15.1", | ||
"liquidjs": "^10.0.0", | ||
"mustache": "^4.0.1", | ||
@@ -67,3 +67,3 @@ "nunjucks": "^3.2.1", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.24.1", | ||
"tsd": "^0.25.0", | ||
"twig": "^1.13.3" | ||
@@ -70,0 +70,0 @@ }, |
@@ -36,3 +36,3 @@ import { FastifyPluginCallback } from 'fastify'; | ||
}; | ||
templates?: string; | ||
templates?: string | string[]; | ||
includeViewExtension?: boolean; | ||
@@ -39,0 +39,0 @@ options?: object; |
@@ -72,1 +72,23 @@ import fastify from "fastify"; | ||
expectDeprecated({} as PointOfViewOptions) | ||
const nunjucksApp = fastify() | ||
nunjucksApp.register(fastifyView, { | ||
engine: { | ||
nunjucks: require('nunjucks'), | ||
}, | ||
templates: [ | ||
'templates/nunjucks-layout', | ||
'templates/nunjucks-template' | ||
], | ||
}) | ||
nunjucksApp.get('/', (request, reply) => { | ||
reply.view('index.njk', { text: 'Sample data' }) | ||
}) | ||
expectType<Promise<string>>(nunjucksApp.view('/', { text: 'Hello world' })) | ||
expectAssignable<FastifyViewOptions>({ engine: { nunjucks: require('nunjucks') }, templates: 'templates' }) | ||
expectAssignable<FastifyViewOptions>({ engine: { nunjucks: require('nunjucks') }, templates: ['templates/nunjucks-layout', 'templates/nunjucks-template']}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284012
8208