Whiskers: Support conditional value parameters for lists

This commit is contained in:
Mathias Baumann 2021-10-12 15:24:55 +02:00
parent b0a5b92fe9
commit 76f31e2c4e
2 changed files with 11 additions and 8 deletions

View File

@ -189,11 +189,13 @@ string Whiskers::replace(
if (conditionName[0] == '+') if (conditionName[0] == '+')
{ {
string tag = conditionName.substr(1); string tag = conditionName.substr(1);
assertThrow(
_parameters.count(tag), if (_parameters.count(tag))
WhiskersError, "Tag " + tag + " used as condition but was not set." conditionValue = !_parameters.at(tag).empty();
); else if (_listParameters.count(tag))
conditionValue = !_parameters.at(tag).empty(); conditionValue = !_listParameters.at(tag).empty();
else
assertThrow(false, WhiskersError, "Tag " + tag + " used as condition but was not set.");
} }
else else
{ {

View File

@ -60,12 +60,13 @@ DEV_SIMPLE_EXCEPTION(WhiskersError);
* - Condition parameter: <?name>...<!name>...</name>, where "<!name>" is optional * - Condition parameter: <?name>...<!name>...</name>, where "<!name>" is optional
* replaced (and recursively expanded) by the first part if the condition is true * replaced (and recursively expanded) by the first part if the condition is true
* and by the second (or empty string if missing) if the condition is false * and by the second (or empty string if missing) if the condition is false
* - Conditional string parameter: <?+name>...<!+name>...</+name>
* Works similar to a conditional parameter where the checked condition is
* that the regular (string) parameter called "name" is non-empty.
* - List parameter: <#list>...</list> * - List parameter: <#list>...</list>
* The part between the tags is repeated as often as values are provided * The part between the tags is repeated as often as values are provided
* in the mapping. Each list element can have its own parameter -> value mapping. * in the mapping. Each list element can have its own parameter -> value mapping.
* - Conditional value parameter: <?+name>...<!+name>...</+name>
* Works similar to a conditional parameter where the checked condition is
* that the string or list parameter called "name" is non-empty or contains
* no elements respectively.
*/ */
class Whiskers class Whiskers
{ {