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 match = _pathRegex.firstMatch(key);

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

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

  if (contextValue == null) {
    throw Exception('Path not found for with: $path');
  }

  // If contextValue is not a Map, we can't change context
  if (contextValue is! Map<String, dynamic>) {
    throw Exception('With requires a Map context, got: ${contextValue.runtimeType}');
  }

  // Process the value with the new context (merging with existing context)
  final result = replaceRecursive(
    value,
    extraContext: contextValue,
  );

  return {cleanKey: result};
}