dots/.dotter/handlebars_helpers/flatten_table.rhai

30 lines
505 B
Text

/*
* Flatten a table into a list of values.
* The table has to be in the form of
* ```toml
* [table.subtable]
* variable1 = ["value1", "value2"]
*
* [table.subtable]
* variable2 = ["value3", "value4"]
*
* then we use it in handlerbars like this:
*
* {{ flatten_table table.subtable }}
*
* and it will return an array with all the arrays of subtable
*/
if type_of(params[0]) != "map" {
return;
}
let table = params[0];
let result = [];
for value in table.values() {
result.append(value);
}
result