From 0f6f004ca1ed102d5282ce57f89c4f6d340df862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Fri, 15 Dec 2017 06:46:06 +0100 Subject: [PATCH] Twig function osmDateParse() --- doc/TwigJS.md | 1 + package.json | 1 + src/twigFunctions.js | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/doc/TwigJS.md b/doc/TwigJS.md index a3b81f10..bc740b14 100644 --- a/doc/TwigJS.md +++ b/doc/TwigJS.md @@ -26,6 +26,7 @@ There are several extra functions defined for the TwigJS language: Extra filters: * filter websiteUrl: return a valid http link. Example: `{{ "www.google.com"|websiteUrl }}` -> "http://www.google.com"; `{{ "https://google.com"|websiteUrl }}` -> "https://google.com" * filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. Returns null if it does not match. +* 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. Notes: * Variables will automatically be HTML escaped, if not the filter raw is used, e.g.: {{ tags.name|raw }} diff --git a/package.json b/package.json index ca59bcb6..40b06373 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "moment": "^2.18.1", "opening_hours": "^3.5.0", "openstreetbrowser-categories-main": "https://github.com/plepe/openstreetbrowser-categories-main", + "openstreetmap-date-parser": "^0.1.0", "openstreetmap-tag-translations": "https://github.com/plepe/openstreetmap-tag-translations", "overpass-layer": "https://github.com/plepe/overpass-layer", "query-string": "^5.0.0", diff --git a/src/twigFunctions.js b/src/twigFunctions.js index 7fe9fdfe..2a51c7ef 100644 --- a/src/twigFunctions.js +++ b/src/twigFunctions.js @@ -1,6 +1,7 @@ var OverpassLayer = require('overpass-layer') var OpeningHours = require('opening_hours') var colorInterpolate = require('color-interpolate') +var osmParseDate = require('openstreetmap-date-parser') OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) { var ret = {} @@ -44,6 +45,9 @@ OverpassLayer.twig.extendFunction('colorInterpolate', function (map, value) { var colormap = colorInterpolate(map) return colormap(value) }) +OverpassLayer.twig.extendFilter('osmParseDate', function (value) { + return osmParseDate(value) +}) OverpassLayer.twig.extendFunction('evaluate', function (tags) { var ob = { id: 'x0',