From 2731c648567f871047d40f00802890c2ada6baae Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 22 Jun 2022 11:09:52 +0200 Subject: [PATCH] Improve documentation of Tags_format, add a few backlinks, see #887 --- Docs/Tags_format.md | 10 +++++++--- Logic/Tags/TagUtils.ts | 1 + Models/ThemeConfig/Json/TagConfigJson.ts | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Docs/Tags_format.md b/Docs/Tags_format.md index 9c2231c657..52ad0e3c2d 100644 --- a/Docs/Tags_format.md +++ b/Docs/Tags_format.md @@ -4,6 +4,8 @@ Tags format When creating the `json` file describing your layer or theme, you'll have to add a few tags to describe what you want. This document gives an overview of what every expression means and how it behaves in edge cases. +If the schema-files note a type `string | AndOrTagConfigJson`, you can use one of these values. + Strict equality --------------- @@ -38,8 +40,8 @@ If `key` is not present or empty, this will match too. This implies that, to check if a key is present, `key!=` can be used. This will only match if the key is present and not empty. -Number comparison ------------------ +Number and date comparison +-------------------------- If the value of a tag is a number (e.g. `key=42`), one can use a filter `key<=42`, `key>=35`, `key>40` or `key<50` to match this, e.g. in conditions for renderings. These tags cannot be used to generate an answer nor can they be used to @@ -51,6 +53,8 @@ special circumstances (e.g. `surface_area=42 m2` or `length=100 feet`), this wil values (`surface=422` or if a length in meters is compared to). However, this can be partially alleviated by using ' Units' to rewrite to a default format. +Dates can be compared with the same expression: `somekey<2022-06-22` will match if `somekey` is a date and is smaller then 22nd june '22. + Regex equals ------------ @@ -87,7 +91,7 @@ To mitigate this, use: { "mappings": [ { - "if":"key:={some_other_key}" + "if":"key:={some_other_key}", "then": "...", "hideInAnswer": "some_other_key=" } diff --git a/Logic/Tags/TagUtils.ts b/Logic/Tags/TagUtils.ts index fb6aa22b75..1f9a6a7154 100644 --- a/Logic/Tags/TagUtils.ts +++ b/Logic/Tags/TagUtils.ts @@ -182,6 +182,7 @@ export class TagUtils { /** * Returns wether or not a keys is (probably) a valid key. + * See 'Tags_format.md' for an overview of what every tag does * * // should accept common keys * TagUtils.isValidKey("name") // => true diff --git a/Models/ThemeConfig/Json/TagConfigJson.ts b/Models/ThemeConfig/Json/TagConfigJson.ts index 90e833178d..ab3d1a9ce9 100644 --- a/Models/ThemeConfig/Json/TagConfigJson.ts +++ b/Models/ThemeConfig/Json/TagConfigJson.ts @@ -1,3 +1,8 @@ +/** + * A small interface to combine tags and tagsfilters. + * + * See https://github.com/pietervdvn/MapComplete/blob/develop/Docs/Tags_format.md for documentation + */ export interface AndOrTagConfigJson { and?: (string | AndOrTagConfigJson)[] or?: (string | AndOrTagConfigJson)[]