diff --git a/umap/static/umap/js/modules/urls.js b/umap/static/umap/js/modules/urls.js index fd3d4b5f..bdf54363 100644 --- a/umap/static/umap/js/modules/urls.js +++ b/umap/static/umap/js/modules/urls.js @@ -1,4 +1,19 @@ -import { Util } from '../../vendors/leaflet/leaflet-src.esm.js' +// Vendorized from leaflet.utils +// https://github.com/Leaflet/Leaflet/blob/108c6717b70f57c63645498f9bd66b6677758786/src/core/Util.js#L132-L151 +var templateRe = /\{ *([\w_ -]+) *\}/g + +function template(str, data) { + return str.replace(templateRe, function (str, key) { + var value = data[key] + + if (value === undefined) { + throw new Error('No value provided for variable ' + str) + } else if (typeof value === 'function') { + value = value(data) + } + return value + }) +} export default class URLs { constructor(serverUrls) { @@ -9,7 +24,7 @@ export default class URLs { if (typeof this[urlName] === 'function') return this[urlName](params) if (this.urls.hasOwnProperty(urlName)) { - return Util.template(this.urls[urlName], params) + return template(this.urls[urlName], params) } else { throw `Unable to find a URL for route ${urlName}` } diff --git a/umap/static/umap/test/URLs.js b/umap/static/umap/unittests/URLs.js similarity index 95% rename from umap/static/umap/test/URLs.js rename to umap/static/umap/unittests/URLs.js index ccd8a91b..5ad50115 100644 --- a/umap/static/umap/test/URLs.js +++ b/umap/static/umap/unittests/URLs.js @@ -1,3 +1,8 @@ +import { describe, it } from 'mocha' + +import pkg from 'chai' +const { expect, assert } = pkg + import URLs from '../js/modules/urls.js' describe('URLs', () => {