apply method

  1. @override
Future<String> apply(
  1. String content,
  2. Map<String, dynamic> context
)
override

Implementation

@override
Future<String> apply(String content, Map<String, dynamic> context) async {
  return content.replaceAllMapped(_configRegex, (match) {
    final key = match.group(1)!.trim();
    final defaultValue = match.group(2)?.trim();

    // Remove quotes if present
    final cleanKey = key.replaceAll('"', '').replaceAll("'", '');

    try {
      // Try to get the configuration value
      final configValue = Khadem.config.get<String>(cleanKey);
      if (configValue != null) {
        return configValue;
      }

      // If not found and default value provided, return it
      if (defaultValue != null) {
        final cleanDefault =
            defaultValue.replaceAll('"', '').replaceAll("'", '');
        return cleanDefault;
      }
    } catch (_) {
      // If there's an error, return default value
      if (defaultValue != null) {
        final cleanDefault =
            defaultValue.replaceAll('"', '').replaceAll("'", '');
        return cleanDefault;
      }
    }

    return '';
  });
}