Refactoring: convert some docs into simple strings

This commit is contained in:
Pieter Vander Vennet 2024-10-07 01:27:44 +02:00
parent 278590ae62
commit 8e548be3d3
2 changed files with 55 additions and 67 deletions

View file

@ -1,40 +1,27 @@
import Combine from "../../Base/Combine"
import Title from "../../Base/Title"
import Table from "../../Base/Table"
import { Validator } from "../Validator" import { Validator } from "../Validator"
import MarkdownUtils from "../../../Utils/MarkdownUtils"
export default class OpeningHoursValidator extends Validator { export default class OpeningHoursValidator extends Validator {
constructor() { constructor() {
super( super(
"opening_hours", "opening_hours",
new Combine([ [
"Has extra elements to easily input when a POI is opened.", "Has extra elements to easily input when a POI is opened.",
new Title("Helper arguments"), ("### Helper arguments"),
new Table( "Only one helper argument named `options` can be provided. It is a JSON-object of type `{ prefix: string, postfix: string }`:",
["name", "doc"], MarkdownUtils.table(
[
[
"options",
new Combine([
"A JSON-object of type `{ prefix: string, postfix: string }`. ",
new Table(
["subarg", "doc"], ["subarg", "doc"],
[ [
[ [
"prefix", "prefix",
"Piece of text that will always be added to the front of the generated opening hours. If the OSM-data does not start with this, it will fail to parse.", "Piece of text that will always be added to the front of the generated opening hours. If the OSM-data does not start with this, it will fail to parse."
], ],
[ [
"postfix", "postfix",
"Piece of text that will always be added to the end of the generated opening hours", "Piece of text that will always be added to the end of the generated opening hours"
],
] ]
),
]), ]),
], ("### Example usage"),
]
),
new Title("Example usage"),
"To add a conditional (based on time) access restriction:\n\n```\n" + "To add a conditional (based on time) access restriction:\n\n```\n" +
` `
"freeform": { "freeform": {
@ -47,8 +34,8 @@ export default class OpeningHoursValidator extends Validator {
} }
] ]
}` + }` +
"\n```\n\n*Don't forget to pass the prefix and postfix in the rendering as well*: `{opening_hours_table(opening_hours,yes @ &LPARENS, &RPARENS )`", "\n```\n\n*Don't forget to pass the prefix and postfix in the rendering as well*: `{opening_hours_table(opening_hours,yes @ &LPARENS, &RPARENS )`"
]) ].join("\n")
) )
} }
} }

View file

@ -10,49 +10,49 @@ import MarkdownUtils from "../../../Utils/MarkdownUtils"
export default class WikidataValidator extends Validator { export default class WikidataValidator extends Validator {
public static readonly _searchCache = new Map<string, Promise<WikidataResponse[]>>() public static readonly _searchCache = new Map<string, Promise<WikidataResponse[]>>()
public static docs = new Combine([ public static docs = [
new Title("Helper arguments"), "### Helper arguments",
new Table( MarkdownUtils.table(
["name", "doc"], ["name", "doc"],
[ [
[ [
"key", "key",
"the value of this tag will initialize search (default: name). This can be a ';'-separated list in which case every key will be inspected. The non-null value will be used as search", "the value of this tag will initialize search (default: name). This can be a ';'-separated list in which case every key will be inspected. The non-null value will be used as search"
], ],
[ [
"options", "options",
new Combine([ "A JSON-object of type `{ removePrefixes: Record<string, string[]>, removePostfixes: Record<string, string[]>, ... }`. See the more detailed explanation below"
"A JSON-object of type `{ removePrefixes: string[], removePostfixes: string[] }`.", ]
]
),
"#### Suboptions",
MarkdownUtils.table( MarkdownUtils.table(
["subarg", "doc"], ["subarg", "doc"],
[ [
[ [
"removePrefixes", "removePrefixes",
"remove these snippets of text from the start of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes", "remove these snippets of text from the start of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes"
], ],
[ [
"removePostfixes", "removePostfixes",
"remove these snippets of text from the end of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes.", "remove these snippets of text from the end of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes."
], ],
[ [
"instanceOf", "instanceOf",
"A list of Q-identifier which indicates that the search results _must_ be an entity of this type, e.g. [`Q5`](https://www.wikidata.org/wiki/Q5) for humans", "A list of Q-identifier which indicates that the search results _must_ be an entity of this type, e.g. [`Q5`](https://www.wikidata.org/wiki/Q5) for humans"
], ],
[ [
"notInstanceof", "notInstanceof",
"A list of Q-identifiers which indicates that the search results _must not_ be an entity of this type, e.g. [`Q79007`](https://www.wikidata.org/wiki/Q79007) to filter away all streets from the search results", "A list of Q-identifiers which indicates that the search results _must not_ be an entity of this type, e.g. [`Q79007`](https://www.wikidata.org/wiki/Q79007) to filter away all streets from the search results"
], ],
[ [
"multiple", "multiple",
"If 'yes' or 'true', will allow to select multiple values at once", "If 'yes' or 'true', will allow to select multiple values at once"
],
] ]
),
]),
],
] ]
), )
new Title("Example usage"), ].join("\n\n")
private static readonly docsExampleUsage: string = "### Example usage\n\n" +
`The following is the 'freeform'-part of a layer config which will trigger a search for the wikidata item corresponding with the name of the selected feature. It will also remove '-street', '-square', ... if found at the end of the name `The following is the 'freeform'-part of a layer config which will trigger a search for the wikidata item corresponding with the name of the selected feature. It will also remove '-street', '-square', ... if found at the end of the name
\`\`\`json \`\`\`json
@ -94,10 +94,11 @@ Another example is to search for species and trees:
}] }]
} }
\`\`\` \`\`\`
`, `
])
constructor() { constructor() {
super("wikidata", new Combine(["A wikidata identifier, e.g. Q42.", WikidataValidator.docs])) super("wikidata", "A wikidata identifier, e.g. Q42.\n\n" + WikidataValidator.docs + WikidataValidator.docsExampleUsage)
} }
public isValid(str): boolean { public isValid(str): boolean {