2022-02-28 18:52:28 +01:00
|
|
|
/**
|
|
|
|
* Rewrites and multiplies the given renderings of type T.
|
2022-09-08 21:40:48 +02:00
|
|
|
*
|
2022-06-19 13:55:33 +02:00
|
|
|
* This can be used for introducing many similar questions automatically,
|
|
|
|
* which also makes translations easier.
|
2022-09-08 21:40:48 +02:00
|
|
|
*
|
|
|
|
* (Note that the key does _not_ need to be wrapped in {}.
|
2022-06-19 13:55:33 +02:00
|
|
|
* However, we recommend to use them if the key is used in a translation, as missing keys will be picked up and warned for by the translation scripts)
|
2022-09-08 21:40:48 +02:00
|
|
|
*
|
2022-02-28 18:52:28 +01:00
|
|
|
* For example:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* rewrite: {
|
|
|
|
* sourceString: ["key", "a|b|c"],
|
|
|
|
* into: [
|
2022-04-03 02:37:31 +02:00
|
|
|
* ["X", 0]
|
|
|
|
* ["Y", 1],
|
|
|
|
* ["Z", 2]
|
2022-02-28 18:52:28 +01:00
|
|
|
* ],
|
2022-06-19 13:55:33 +02:00
|
|
|
* renderings: [{
|
2022-02-28 18:52:28 +01:00
|
|
|
* "key":"a|b|c"
|
2022-06-19 13:55:33 +02:00
|
|
|
* }]
|
2022-02-28 18:52:28 +01:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
* will result in _three_ copies (as the values to rewrite into have three values, namely:
|
2022-09-08 21:40:48 +02:00
|
|
|
*
|
2022-02-28 18:52:28 +01:00
|
|
|
* [
|
|
|
|
* {
|
2022-06-13 00:51:53 +02:00
|
|
|
* # The first pair: key --> X, a|b|c --> 0
|
2022-02-28 18:52:28 +01:00
|
|
|
* "X": 0
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* "Y": 1
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* "Z": 2
|
|
|
|
* }
|
2022-09-08 21:40:48 +02:00
|
|
|
*
|
2022-02-28 18:52:28 +01:00
|
|
|
* ]
|
2022-09-08 21:40:48 +02:00
|
|
|
*
|
2022-04-03 02:37:31 +02:00
|
|
|
* @see ExpandRewrite
|
2022-02-28 18:52:28 +01:00
|
|
|
*/
|
2022-02-28 17:17:38 +01:00
|
|
|
export default interface RewritableConfigJson<T> {
|
|
|
|
rewrite: {
|
2022-09-08 21:40:48 +02:00
|
|
|
sourceString: string[]
|
2022-02-28 17:17:38 +01:00
|
|
|
into: (string | any)[][]
|
2022-09-08 21:40:48 +02:00
|
|
|
}
|
2024-06-03 15:29:53 +02:00
|
|
|
/**
|
|
|
|
* Used to expand a sublist.
|
|
|
|
* E.g. a target `rendering` is:
|
|
|
|
*
|
|
|
|
* e.g.
|
|
|
|
* {
|
|
|
|
* rewrite: ["{{x}}", "{{y}}"],
|
|
|
|
* into:[
|
|
|
|
* ["{{x}}": "some X"],
|
|
|
|
* ["{{y}}", ["option 1", "option 2"]]
|
|
|
|
* ],
|
|
|
|
* renderings:[
|
|
|
|
* {
|
|
|
|
* "question":"Is {{x}}",
|
|
|
|
* "mappings": ["if={{y}}",then: "..."]
|
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* subExpand: {
|
|
|
|
* // The list with the key
|
|
|
|
* "mappings":
|
|
|
|
* // will be taken and multiplied by all possible values of
|
|
|
|
* "{{y}}"
|
|
|
|
* // Note that this implies that `into.[*].[{{y}}]` should be a list of items
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Expansion will result in:
|
|
|
|
* {
|
|
|
|
* question: "Is some X",
|
|
|
|
* mappings: [{"if=option 1", then: "..."}, {"if=option 2", then: "..."}]
|
|
|
|
* }
|
|
|
|
*/
|
2023-12-12 03:43:55 +01:00
|
|
|
subexpand?: Record<string, string[]>
|
|
|
|
renderings: T | T[]
|
2022-09-08 21:40:48 +02:00
|
|
|
}
|