index.js
function resolveLayout(file, layout, options, regex, name) {
  if (typeOf(layout.contents) !== 'buffer') {
    throw new Error('expected layout.contents to be a buffer');
  }

  // reset lastIndex, since regex is cached
  regex.lastIndex = 0;

  const layoutString = toString(layout, options);
  if (!regex.test(layoutString)) {
    throw new Error(`cannot find tag "${regex.source}" in layout "${name}"`);
  }

  const fileString = toString(file, options);
  let str;

  if (options.preserveWhitespace === true) {
    const re = new RegExp('(?:^(\\s+))?' + regex.source, 'gm');
    let lines;

    str = layoutString.replace(re, function(m, whitespace) {
      if (whitespace) {
        lines = lines || fileString.split('\n'); // only split once, JIT
        return lines.map(line => whitespace + line).join('\n');
      }
      return fileString;
    });

  } else {
    str = Buffer.from(layoutString.replace(regex, () => fileString));
  }

  file.contents = Buffer.from(str);
  return getLayoutName(layout, options);
}
function resolveLayout(file, layout, options, regex, name) {
  if (typeOf(layout.contents) !== 'buffer') {
    throw new Error('expected layout.contents to be a buffer');
  }

  // reset lastIndex, since regex is cached
  regex.lastIndex = 0;

  const layoutString = toString(layout, options);
  if (!regex.test(layoutString)) {
    throw new Error(`cannot find tag "${regex.source}" in layout "${name}"`);
  }

  const fileString = toString(file, options);
  let str;

  if (options.preserveWhitespace === true) {
    const re = new RegExp('(?:^(\\s+))?' + regex.source, 'gm');
    let lines;

    str = layoutString.replace(re, function(m, whitespace) {
      if (whitespace) {
        lines = lines || fileString.split('\n'); // only split once, JIT
        return lines.map(line => whitespace + line).join('\n');
      }
      return fileString;
    });

  } else {
    str = Buffer.from(layoutString.replace(regex, () => fileString));
  }

  file.contents = Buffer.from(str);
  return getLayoutName(layout, options);
}
function resolveLayout ( file , layout , options , regex , name ) { if ( typeOf ( layout . contents ) !== 'buffer' ) { throw new Error ( 'expected layout.contents to be a buffer' ) ; } // reset lastIndex, since regex is cached regex . lastIndex = 0 ; const layoutString = toString ( layout , options ) ; if ( ! regex . test ( layoutString ) ) { throw new Error ( ` ${ regex . source } ${ name } ` ) ; } const fileString = toString ( file , options ) ; let str ; if ( options . preserveWhitespace === true ) { const re = new RegExp ( '(?:^(\\s+))?' + regex . source , 'gm' ) ; let lines ; str = layoutString . replace ( re , function ( m , whitespace ) { if ( whitespace ) { lines = lines || fileString . split ( '\n' ) ; // only split once, JIT return lines . map ( line => whitespace + line ) . join ( '\n' ) ; } return fileString ; } ) ; } else { str = Buffer . from ( layoutString . replace ( regex , ( ) => fileString ) ) ; } file . contents = Buffer . from ( str ) ; return getLayoutName ( layout , options ) ; }
Apply the current layout, and resolve the name of the next layout to apply.
Apply the current layout and resolve the name of the next layout to apply .