Browse Source

twig: new filter 'md5'

master
parent
commit
8ee34368d8
  1. 1
      doc/TwigJS.md
  2. 1
      package.json
  3. 10
      src/twigFunctions.js

1
doc/TwigJS.md

@ -67,6 +67,7 @@ Extra filters:
* filter `osmDateParse`: returns an array with the lower and upper boundary of the year of a `start_date` tag. See [https://github.com/plepe/openstreetmap-date-parser](openstreetmap-date-parser) for details.
* filter `natsort`: Sort an array naturally, see [https://www.npmjs.com/package/natsort](natsort) for details.
* filter `unique`: Remove duplicate elements from an array.
* filter `md5`: calculate md5 hash of a string.
Notes:
* Variables will automatically be HTML escaped, if not the filter raw is used, e.g.: {{ tags.name|raw }}

1
package.json

@ -21,6 +21,7 @@
"leaflet-textpath": "https://github.com/makinacorpus/Leaflet.TextPath#leaflet0.8-dev",
"leaflet.locatecontrol": "^0.61.0",
"leaflet.polylinemeasure": "https://github.com/ppete2/Leaflet.PolylineMeasure.git",
"md5": "^2.2.1",
"modulekit-tabs": "^0.1.0",
"moment": "^2.18.1",
"natsort": "^1.0.6",

10
src/twigFunctions.js

@ -3,6 +3,9 @@ var OpeningHours = require('opening_hours')
var colorInterpolate = require('color-interpolate')
var osmParseDate = require('openstreetmap-date-parser')
const natsort = require('natsort')
const md5 = require('md5')
var md5cache = {}
OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
var ret = {}
@ -59,6 +62,13 @@ OverpassLayer.twig.extendFunction('colorInterpolate', function (map, value) {
OverpassLayer.twig.extendFilter('osmParseDate', function (value) {
return osmParseDate(value)
})
OverpassLayer.twig.extendFilter('md5', function (value) {
if (value in md5cache) {
return md5cache[value]
}
return md5cache[value] = md5(value)
})
OverpassLayer.twig.extendFunction('evaluate', function (tags) {
var ob = {
id: 'x0',

Loading…
Cancel
Save