configurePath method
updates the file path with the provided urls
and dirs
replacing the appropriate segments and file name
Implementation
@override
ContentReplacement configurePath({
required Iterable<Url> urls,
required Iterable<Directory> dirs,
}) {
final variablesUsed = <String>{};
var newPath = pathWithoutSourceDir;
newPath = newPath.replaceAll(p.basename(newPath), '');
Url? url;
final urlPaths = {
for (final url in urls) url.path: url,
};
if (urlPaths.containsKey(sourcePath)) {
url = urlPaths[sourcePath];
variablesUsed.addAll(url!.vars);
newPath = p.join(newPath, url.formatName());
variablesUsed.addAll(url.name?.vars ?? []);
} else {
newPath = p.join(newPath, formatName());
variablesUsed
..addAll(name?.vars ?? [])
..addAll(include?.vars ?? []);
}
variablesUsed.addAll(name?.vars ?? []);
if (Patterns.pathSeparator.hasMatch(newPath)) {
for (final configDir in dirs) {
final comparePath = newPath;
newPath = configDir.apply(
newPath,
pathWithoutSourceDir: pathWithoutSourceDir,
);
if (newPath != comparePath) {
variablesUsed.addAll(configDir.vars);
}
}
}
return ContentReplacement(
content: newPath,
used: variablesUsed,
data: {
'url': url,
},
);
}