templateResource function

String templateResource(
  1. String path,
  2. Map<String, dynamic> params,
  3. {String prefix = _defaultPrefix}
)

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 the prefix by default).
  • Map<String, dynamic> params - the template replacement values.
  • String prefix - the path prefix from the project root (defaults to test/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;
}