call method

  1. @override
Map<String, dynamic> call(
  1. String key,
  2. dynamic value,
  3. GetValueFromPathFunction getValue,
  4. ReplaceRecursiveFunction replaceRecursive,
  5. Map<String, String>? templates,
)
override

Implementation

@override
Map<String, dynamic> call(
  String key,
  value,
  GetValueFromPathFunction getValue,
  ReplaceRecursiveFunction replaceRecursive,
  Map<String, String>? templates,
) {
  final cleanKey = clearKey(key);

  final regex = RegExp(r'\{\{#map:([^}]+)\}\}');
  final match = regex.firstMatch(key);

  if (match == null) {
    throw Exception('Invalid map syntax: $key');
  }

  final path = match.group(1)!;
  final items = getValue(path);

  if (items is! List) {
    throw Exception('Path does not point to a list: $path');
  }

  final result = items.map((item) {
    return replaceRecursive(
      value,
      extraContext: {'item': item},
    );
  }).toList();

  return {cleanKey: result};
}