Browse Source

Twig Function 'openingHoursState'

master
parent
commit
e4f539a29f
  1. 1
      README.md
  2. 2
      lang/de.json
  3. 2
      lang/en.json
  4. 3
      package.json
  5. 6
      src/twigFunctions.js

1
README.md

@ -132,6 +132,7 @@ There are several extra functions defined for the TwigJS language:
* function `localizedTag`: return a localized tag if available (e.g. 'name:de' for the german translation of the tag). Parameters: tags (the tags property), key prefix (e.g. 'name'). Which language will be returned depends on the "data language" which can be set via Options. If no localized tag is available, the tag value itself will be returned (e.g. value of 'name').
* function `trans`: return the translation of the given string (e.g. 'save', 'unknown', 'unnamed', ...). Parameters: string (the string to translate).
* 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'.
Notes:
* Variables will automatically be HTML escaped, if not the filter raw is used, e.g.: {{ tags.name|raw }}

2
lang/de.json

@ -1,6 +1,8 @@
{
"closed": "geschlossen",
"default": "Standard",
"main:options": "Optionen",
"open": "geöffnet",
"options:data_lang": "Datensprache",
"options:data_lang:local": "Lokale Sprache",
"options:overpassUrl": "OverpassAPI Adresse",

2
lang/en.json

@ -1,6 +1,8 @@
{
"closed": "closed",
"default": "default",
"main:options": "Options",
"open": "open",
"options:data_lang": "Data language",
"options:data_lang:desc": "Many map features have their name (and other tags) translated to different languages (e.g. with 'name:en', 'name:de'). Specify which language should be used for displaying, or 'Local language' so that always the untranslated value (e.g. 'name') will be used",
"options:data_lang:local": "Local language",

3
package.json

@ -8,10 +8,13 @@
"license": "GPL-3.0",
"dependencies": {
"font-awesome": "^4.7.0",
"i18next-client": "^1.11.4",
"ip-location": "^1.0.1",
"leaflet": "^1.0.3",
"leaflet-geosearch": "^2.4.0",
"leaflet.locatecontrol": "^0.61.0",
"moment": "^2.18.1",
"opening_hours": "^3.5.0",
"openstreetbrowser-categories-main": "https://github.com/plepe/openstreetbrowser-categories-main",
"openstreetmap-tag-translations": "https://github.com/plepe/openstreetmap-tag-translations",
"overpass-layer": "https://github.com/plepe/overpass-layer",

6
src/twigFunctions.js

@ -1,4 +1,5 @@
var OverpassLayer = require('overpass-layer')
var OpeningHours = require('opening_hours')
OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
var ret = {}
@ -17,3 +18,8 @@ OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
return ret
})
OverpassLayer.twig.extendFunction('openingHoursState', function (opening_hours) {
var oh = new OpeningHours(opening_hours)
return oh.getStateString(new Date(), true)
})
Loading…
Cancel
Save