From 6df44a9e20539f6e75faf9dfa92396ce9ac07ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 17 Sep 2017 21:47:12 +0200 Subject: [PATCH] Twig filter 'matches' --- doc/TwigJS.md | 3 +++ src/twigFunctions.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/doc/TwigJS.md b/doc/TwigJS.md index 5f4d01b3..2a3a9779 100644 --- a/doc/TwigJS.md +++ b/doc/TwigJS.md @@ -22,6 +22,9 @@ There are several extra functions defined for the TwigJS language: * function `tagsPrefix(tags, prefix)`: return all tags with the specified prefix. The result will be an array with `{ "en": "name:en", "de": "name:de" }` (for the input `{ "name": "foo", "name:en": "english foo", "name:de": "german foo" }` and the prefix "name:"). * function openingHoursState(opening_hours_definition): returns state of object as string: 'closed', 'open' or 'unknown'. +Extra filters: +* filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. Returns null if it does not match. + Notes: * Variables will automatically be HTML escaped, if not the filter raw is used, e.g.: {{ tags.name|raw }} * The templates will be rendered when the object becomes visible and when the zoom level changes. diff --git a/src/twigFunctions.js b/src/twigFunctions.js index 68f84caf..2a289706 100644 --- a/src/twigFunctions.js +++ b/src/twigFunctions.js @@ -29,3 +29,6 @@ OverpassLayer.twig.extendFunction('openingHoursState', function (openingHours) { return oh.getStateString(new Date(), true) }) +OverpassLayer.twig.extendFilter('matches', function (value, match) { + return value.match(match) +})