Nunjucks/globals: fix route() context

This commit is contained in:
Alice Gaudon 2020-10-02 12:13:34 +02:00
parent 8cf069fb28
commit 93bff1fdca
2 changed files with 11 additions and 3 deletions

View File

@ -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 <alice@gaudon.pro>",

View File

@ -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)