src/inject/index.js
function getNewContent(target, collection, opt) {
  var logger = opt.quiet ? noop : function (filesCount) {
    if (filesCount) {
      var pluralState = filesCount > 1 ? 's' : '';
      log(cyan(filesCount) + ' file' + pluralState + ' into ' + magenta(target.relative) + '.');
    } else {
      log('Nothing to inject into ' + magenta(target.relative) + '.');
    }
  };
  var content = String(target.contents);
  var targetExt = extname(target.path);
  var files = prepareFiles(collection, targetExt, opt, target);
  var filesPerTags = groupArray(files, 'tagKey');
  var startAndEndTags = Object.keys(filesPerTags);
  var matches = [];
  var injectedFilesCount = 0;

  startAndEndTags.forEach(function (tagKey) {
    var files = filesPerTags[tagKey];
    var startTag = files[0].startTag;
    var endTag = files[0].endTag;
    var tagsToInject = getTagsToInject(files, target, opt);
    content = inject(content, {
      startTag: startTag,
      endTag: endTag,
      tagsToInject: tagsToInject,
      removeTags: opt.removeTags,
      empty: opt.empty,
      willInject: function (filesToInject) {
        injectedFilesCount += filesToInject.length;
      },
      onMatch: function (match) {
        matches.push(match[0]);
      }
    });
  });

  logger(injectedFilesCount);

  if (opt.empty) {
    var ext = '{{ANY}}';
    var startTag = getTagRegExp(opt.tags.start(targetExt, ext, opt.starttag), ext, opt);
    var endTag = getTagRegExp(opt.tags.end(targetExt, ext, opt.endtag), ext, opt);

    content = inject(content, {
      startTag: startTag,
      endTag: endTag,
      tagsToInject: [],
      removeTags: opt.removeTags,
      empty: opt.empty,
      shouldAbort: function (match) {
        return matches.indexOf(match[0]) !== -1;
      }
    });
  }

  return Buffer.from(content);
}
function getNewContent(target, collection, opt) {
  var logger = opt.quiet ? noop : function (filesCount) {
    if (filesCount) {
      var pluralState = filesCount > 1 ? 's' : '';
      log(cyan(filesCount) + ' file' + pluralState + ' into ' + magenta(target.relative) + '.');
    } else {
      log('Nothing to inject into ' + magenta(target.relative) + '.');
    }
  };
  var content = String(target.contents);
  var targetExt = extname(target.path);
  var files = prepareFiles(collection, targetExt, opt, target);
  var filesPerTags = groupArray(files, 'tagKey');
  var startAndEndTags = Object.keys(filesPerTags);
  var matches = [];
  var injectedFilesCount = 0;

  startAndEndTags.forEach(function (tagKey) {
    var files = filesPerTags[tagKey];
    var startTag = files[0].startTag;
    var endTag = files[0].endTag;
    var tagsToInject = getTagsToInject(files, target, opt);
    content = inject(content, {
      startTag: startTag,
      endTag: endTag,
      tagsToInject: tagsToInject,
      removeTags: opt.removeTags,
      empty: opt.empty,
      willInject: function (filesToInject) {
        injectedFilesCount += filesToInject.length;
      },
      onMatch: function (match) {
        matches.push(match[0]);
      }
    });
  });

  logger(injectedFilesCount);

  if (opt.empty) {
    var ext = '{{ANY}}';
    var startTag = getTagRegExp(opt.tags.start(targetExt, ext, opt.starttag), ext, opt);
    var endTag = getTagRegExp(opt.tags.end(targetExt, ext, opt.endtag), ext, opt);

    content = inject(content, {
      startTag: startTag,
      endTag: endTag,
      tagsToInject: [],
      removeTags: opt.removeTags,
      empty: opt.empty,
      shouldAbort: function (match) {
        return matches.indexOf(match[0]) !== -1;
      }
    });
  }

  return Buffer.from(content);
}
function getNewContent ( target , collection , opt ) { var logger = opt . quiet ? noop : function ( filesCount ) { if ( filesCount ) { var pluralState = filesCount > 1 ? 's' : '' ; log ( cyan ( filesCount ) + ' file' + pluralState + ' into ' + magenta ( target . relative ) + '.' ) ; } else { log ( 'Nothing to inject into ' + magenta ( target . relative ) + '.' ) ; } } ; var content = String ( target . contents ) ; var targetExt = extname ( target . path ) ; var files = prepareFiles ( collection , targetExt , opt , target ) ; var filesPerTags = groupArray ( files , 'tagKey' ) ; var startAndEndTags = Object . keys ( filesPerTags ) ; var matches = [ ] ; var injectedFilesCount = 0 ; startAndEndTags . forEach ( function ( tagKey ) { var files = filesPerTags [ tagKey ] ; var startTag = files [ 0 ] . startTag ; var endTag = files [ 0 ] . endTag ; var tagsToInject = getTagsToInject ( files , target , opt ) ; content = inject ( content , { startTag : startTag , endTag : endTag , tagsToInject : tagsToInject , removeTags : opt . removeTags , empty : opt . empty , willInject : function ( filesToInject ) { injectedFilesCount += filesToInject . length ; } , onMatch : function ( match ) { matches . push ( match [ 0 ] ) ; } } ) ; } ) ; logger ( injectedFilesCount ) ; if ( opt . empty ) { var ext = '{{ANY}}' ; var startTag = getTagRegExp ( opt . tags . start ( targetExt , ext , opt . starttag ) , ext , opt ) ; var endTag = getTagRegExp ( opt . tags . end ( targetExt , ext , opt . endtag ) , ext , opt ) ; content = inject ( content , { startTag : startTag , endTag : endTag , tagsToInject : [ ] , removeTags : opt . removeTags , empty : opt . empty , shouldAbort : function ( match ) { return matches . indexOf ( match [ 0 ] ) !== - 1 ; } } ) ; } return Buffer . from ( content ) ; }
Get new content for template
with all injections made

@param {Object} target
@param {Array} collection
@param {Object} opt
@returns {Buffer}
Get new content for template with all injections made