templateResource function
Retrieves a String
containing the contents of a resource text file with
its template values (surrounded by {{}}
) replaced with the provided map
values.
"Test resources" are files stored (by default) under the test/resources/
directory of the project root. This prefix may be changed, using the
prefix
argument.
Arguments
String path
- the relative path (from theprefix
by default).Map<String, dynamic> params
- the template replacement values.String prefix
- the path prefix from the project root (defaults totest/resources
).
Return
A String
containing the rendered template.
Example
String rendered = templateResource('data/the_template.txt', {'name':'Bob'});
Implementation
String templateResource(
String path,
Map<String, dynamic> params, {
String prefix = _defaultPrefix,
}) {
var template = resourceString(path, prefix: prefix);
params.forEach((key, value) {
template = template.replaceAll('{{$key}}', value.toString());
});
return template;
}