mapGlobal function
Map global template patterns in code to their current values.
Replace Global template patterns with their values. These are not specific to any particular feature.
Implementation
Future<String> mapGlobal(WidgetRef ref, String code) async {
String path = ref.read(pathProvider);
code = code.replaceAll('<TIMESTAMP>', 'Rattle ${timestamp()}');
PackageInfo info = await PackageInfo.fromPlatform();
code = code.replaceAll('<VERSION>', info.version);
// 20240825 lutra Fix the path to the dataset to ensure that the Windows path
// has been correctly converted to a Unix path for R.
if (Platform.isWindows) {
path = path.replaceAll(r'\', '/');
}
code = code.replaceAll('<FILENAME>', path);
code = code.replaceAll('<TEMPDIR>', tempDir);
String package = ref.read(packageProvider);
code = code.replaceAll('<PACKAGE>', package);
String dataset = ref.read(datasetProvider);
code = code.replaceAll('<DATASET>', dataset);
return (code);
}