replaceText method
Replaces the specified id with the specified text value anywhere in the file.
The id can be an AFSourceTemplateInsertion, or it can just be a string. The value can be any text, but it should not contain a newline. This function automatically handles the template parameters modifiers like lower and upper.
Implementation
void replaceText(AFCommandContext context, dynamic id, String value) {
/// go through all lines, looking for the id.
final idCode = id.toString();
for(var i = 0; i < lines.length; i++) {
replaceInLine(context, i, idCode, (ctx, options) {
var result = value;
if(result.contains("\n")) {
final lines = result.split("\n");
return lines;
}
if(options.isEmpty) {
}
else if(options.contains(AFSourceTemplateInsertion.optionLower)) {
result = value.toLowerCase();
}
else if(options.contains(AFSourceTemplateInsertion.optionUpper)) {
result = value.toUpperCase();
}
else if(options.contains(AFSourceTemplateInsertion.optionSnake)) {
result = AFCodeGenerator.convertMixedToSnake(value);
}
else if(options.contains(AFSourceTemplateInsertion.optionCamel)) {
result = AFCodeGenerator.convertToCamelCase(value);
}
else if(options.contains(AFSourceTemplateInsertion.optionSpaces)) {
result = AFCodeGenerator.convertMixedToSpaces(value);
} else if(options.contains(AFSourceTemplateInsertion.optionCamelPluralize)) {
result = AFCodeGenerator.convertToCamelCase(value);
result = AFCodeGenerator.pluralize(result);
} else if(options.contains(AFSourceTemplateInsertion.optionUpperFirst)) {
result = AFCodeGenerator.convertUpcaseFirst(result);
} else {
throw AFCommandError(error: "Unknown option '$options' in tag $idCode");
}
return [result];
});
}
}