inject function
Injects data into an Object
Implementation
String inject(String name, Object data, Object input) {
String result = input.toString();
try {
// Find all placeholders enclosed in <slot> tags
RegExp slotRegExp = RegExp("<$name>(.*?)</$name>");
Iterable<Match> matches = slotRegExp.allMatches(input.toString());
if (data is Map) {
// Iterate over matches and replace with values from params or "X"
for (Match match in matches) {
String slotName = match.group(1)!; // Extract the slot name
String slotValue =
data[slotName].toString(); // Use value from params or "X"
result = result.replaceFirst(match.group(0)!, slotValue);
}
if (result.trim() == "") {
return input.toString();
}
}
} catch (e) {
printLog("Injection Error: $e", true, color: LogColor.red);
}
return result;
}