checkForPartials method

  1. @visibleForTesting
ContentReplacement checkForPartials({
  1. required String content,
  2. required Iterable<Partial> partials,
})

writes the partials to the content

Implementation

@visibleForTesting
ContentReplacement checkForPartials({
  required String content,
  required Iterable<Partial> partials,
}) {
  var newContent = content;

  final partialsUsed = <String>{};

  for (final partial in partials) {
    final partialPattern =
        RegExp(r'.*\bpartials\.' '${partial.name}' r'\b.*');
    final compareContent = newContent;
    newContent =
        newContent.replaceAll(partialPattern, partial.toPartialInput());

    if (compareContent != newContent) {
      partialsUsed.add(partial.fileName);
    }
  }

  return ContentReplacement(content: newContent, used: partialsUsed);
}