createSnippet method
AFCodeBuffer
createSnippet(
- Object source, {
- AFSourceTemplateInsertions? extend,
- Map<
AFSourceTemplateInsertion, Object> ? insertions,
Given a snippet and a set of insertions, returns a code buffer with the insertions replaced.
Implementation
AFCodeBuffer createSnippet(
Object source, {
AFSourceTemplateInsertions? extend,
Map<AFSourceTemplateInsertion, Object>? insertions
}
) {
var fullInsert = this.coreInsertions;
if(extend != null) {
fullInsert = fullInsert.reviseOverwrite(extend.insertions);
}
if(insertions != null) {
fullInsert = fullInsert.reviseOverwrite(insertions);
}
if(source is! AFSourceTemplate) {
throw AFException("Expected AFSnippetSourceTemplate");
}
var effective = source.toBuffer(this, insertions: fullInsert.insertions);
if(source is AFSnippetSourceTemplate) {
// see if the source is overridden
final originalPath = source.templatePath;
final overridePath = this.findOverrideTemplate(originalPath);
final hasOverride = overridePath != originalPath;
if(hasOverride) {
if(AFProjectPaths.generateFileExists(overridePath)) {
effective = AFCodeBuffer.fromGeneratePath(overridePath);
} else {
// if the path changed, and the override path is not on the filesystem, see if it
// is one of our predefined paths.
if(hasOverride) {
final overrideTemplate = findEmbeddedTemplateSnippet(overridePath);
if(overrideTemplate == null) {
throw AFException("The override ${joinAll(overridePath)} was not found on the file system, or in the AFTemplateRegistry, for ${joinAll(originalPath)}");
}
effective = overrideTemplate.toBuffer(this, insertions: fullInsert.insertions);
}
}
}
}
return effective;
}