resolve function

Future<Document?> resolve(
  1. Document document,
  2. Directory currentDirectory, {
  3. void onError(
    1. JaelError error
    )?,
  4. Iterable<Patcher>? patch,
})

Expands all block[name] tags within the template, replacing them with the correct content.

To apply additional patches to resolved documents, provide a set of patch functions.

Implementation

Future<Document?> resolve(Document document, Directory currentDirectory,
    {void Function(JaelError error)? onError, Iterable<Patcher>? patch}) async {
  onError ?? (e) => throw e;

  // Resolve all includes...
  var includesResolved =
      await resolveIncludes(document, currentDirectory, onError);

  var patched = await applyInheritance(
      includesResolved, currentDirectory, onError, patch);

  if (patch?.isNotEmpty != true) {
    return patched;
  }

  for (var p in patch!) {
    patched = await p(patched, currentDirectory, onError);
  }

  return patched;
}