From 93bff1fdcace116a341905a30be4e9580010cc43 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Fri, 2 Oct 2020 12:13:34 +0200 Subject: [PATCH] Nunjucks/globals: fix route() context --- package.json | 2 +- src/components/NunjucksComponent.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 47e3f97..8a95f5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-core", - "version": "0.22.0-rc.23", + "version": "0.22.0-rc.24", "description": "Node web application framework and toolbelt.", "repository": "https://gitlab.com/ArisuOngaku/wms-core", "author": "Alice Gaudon ", diff --git a/src/components/NunjucksComponent.ts b/src/components/NunjucksComponent.ts index 23197f9..79dc4a6 100644 --- a/src/components/NunjucksComponent.ts +++ b/src/components/NunjucksComponent.ts @@ -2,8 +2,9 @@ import nunjucks, {Environment} from "nunjucks"; import config from "config"; import {Express, NextFunction, Request, Response, Router} from "express"; import ApplicationComponent from "../ApplicationComponent"; -import Controller from "../Controller"; +import Controller, {RouteParams} from "../Controller"; import * as querystring from "querystring"; +import {ParsedUrlQueryInput} from "querystring"; import * as util from "util"; import * as path from "path"; import * as fs from "fs"; @@ -40,7 +41,14 @@ export default class NunjucksComponent extends ApplicationComponent { noCache: !config.get('view.cache'), throwOnUndefined: true, }) - .addGlobal('route', Controller.route) + .addGlobal('route', ( + route: string, + params: RouteParams = [], + query: ParsedUrlQueryInput = {}, + absolute: boolean = false, + ): string => { + return Controller.route(route, params, query, absolute); + }) .addGlobal('app_version', this.getApp().getVersion()) .addGlobal('core_version', coreVersion) .addGlobal('querystring', querystring)