index.js
function loadPartials(template, templatePath) {
    var templateDir = path.dirname(templatePath)

    var partialRegexp = new RegExp(
      escapeRegex(mustache.tags[0]) +
        '>\\s*(\\S+)\\s*' +
        escapeRegex(mustache.tags[1]),
      'g'
    )

    var partialMatch
    while ((partialMatch = partialRegexp.exec(template))) {
      var partialName = partialMatch[1]

      if (!partials[partialName]) {
        try {
          var partialPath = null
          var partial = null

          // ignore `partial` with file extension.
          // e.g.
          //   1, `{{> ./path/to/partial.html }}`
          //   2, `{{> ./path/to/partial. }}`
          if (path.extname(partialName) !== '') {
            partialPath = path.resolve(templateDir, partialName)
            partial = fs.readFileSync(partialPath, 'utf8')
          } else {
            // ignore `partial` file is exists without file extension.
            // e.g.
            //   1, `{{> ./path/to/partial }}` is exists.
            //   2, `{{> ./path/to/.partial }}` is exists.
            partialPath = path.resolve(templateDir, partialName)

            if (fs.existsSync(partialPath)) {
              partial = fs.readFileSync(partialPath, 'utf8')
            } else {
              // or check if `partial + options.extension` is exists.
              // e.g.
              //   if `options.extension` equals ".html":
              //   the `{{> ./path/to/partial }}` will load
              //   `./path/to/partial.html`.
              if (typeof options.extension === 'string') {
                partialPath = path.resolve(
                  templateDir,
                  partialName + options.extension
                )

                if (fs.existsSync(partialPath)) {
                  partial = fs.readFileSync(partialPath, 'utf8')
                }
              }

              // when `options.extension` is not a string or
              // `partialName + options.extension` does not exists.
              // try use `.mustache` extension to load `partial` file.
              if (partial === null) {
                partialPath = path.resolve(
                  templateDir,
                  partialName + '.mustache'
                )

                partial = fs.readFileSync(partialPath, 'utf8')
              }
            }
          }

          partials[partialName] = partial
          loadPartials.call(this, partial, partialPath)
        } catch (ex) {
          this.emit(
            'error',
            new PluginError(
              'gulp-mustache',
              // use `ex.message` property instead of `partialPath`,
              // because `this.emit()` seems not a sync method.
              // also the `ex.message` property provide more details
              // about error information.
              'Unable to load partial file: ' + ex.message
            )
          )
        }
      }
    }
  }
function loadPartials(template, templatePath) {
    var templateDir = path.dirname(templatePath)

    var partialRegexp = new RegExp(
      escapeRegex(mustache.tags[0]) +
        '>\\s*(\\S+)\\s*' +
        escapeRegex(mustache.tags[1]),
      'g'
    )

    var partialMatch
    while ((partialMatch = partialRegexp.exec(template))) {
      var partialName = partialMatch[1]

      if (!partials[partialName]) {
        try {
          var partialPath = null
          var partial = null

          // ignore `partial` with file extension.
          // e.g.
          //   1, `{{> ./path/to/partial.html }}`
          //   2, `{{> ./path/to/partial. }}`
          if (path.extname(partialName) !== '') {
            partialPath = path.resolve(templateDir, partialName)
            partial = fs.readFileSync(partialPath, 'utf8')
          } else {
            // ignore `partial` file is exists without file extension.
            // e.g.
            //   1, `{{> ./path/to/partial }}` is exists.
            //   2, `{{> ./path/to/.partial }}` is exists.
            partialPath = path.resolve(templateDir, partialName)

            if (fs.existsSync(partialPath)) {
              partial = fs.readFileSync(partialPath, 'utf8')
            } else {
              // or check if `partial + options.extension` is exists.
              // e.g.
              //   if `options.extension` equals ".html":
              //   the `{{> ./path/to/partial }}` will load
              //   `./path/to/partial.html`.
              if (typeof options.extension === 'string') {
                partialPath = path.resolve(
                  templateDir,
                  partialName + options.extension
                )

                if (fs.existsSync(partialPath)) {
                  partial = fs.readFileSync(partialPath, 'utf8')
                }
              }

              // when `options.extension` is not a string or
              // `partialName + options.extension` does not exists.
              // try use `.mustache` extension to load `partial` file.
              if (partial === null) {
                partialPath = path.resolve(
                  templateDir,
                  partialName + '.mustache'
                )

                partial = fs.readFileSync(partialPath, 'utf8')
              }
            }
          }

          partials[partialName] = partial
          loadPartials.call(this, partial, partialPath)
        } catch (ex) {
          this.emit(
            'error',
            new PluginError(
              'gulp-mustache',
              // use `ex.message` property instead of `partialPath`,
              // because `this.emit()` seems not a sync method.
              // also the `ex.message` property provide more details
              // about error information.
              'Unable to load partial file: ' + ex.message
            )
          )
        }
      }
    }
  }
function loadPartials ( template , templatePath ) { var templateDir = path . dirname ( templatePath ) var partialRegexp = new RegExp ( escapeRegex ( mustache . tags [ 0 ] ) + '>\\s*(\\S+)\\s*' + escapeRegex ( mustache . tags [ 1 ] ) , 'g' ) var partialMatch while ( ( partialMatch = partialRegexp . exec ( template ) ) ) { var partialName = partialMatch [ 1 ] if ( ! partials [ partialName ] ) { try { var partialPath = null var partial = null // ignore `partial` with file extension. // e.g. //   1, `{{> ./path/to/partial.html }}` //   2, `{{> ./path/to/partial. }}` if ( path . extname ( partialName ) !== '' ) { partialPath = path . resolve ( templateDir , partialName ) partial = fs . readFileSync ( partialPath , 'utf8' ) } else { // ignore `partial` file is exists without file extension. // e.g. //   1, `{{> ./path/to/partial }}` is exists. //   2, `{{> ./path/to/.partial }}` is exists. partialPath = path . resolve ( templateDir , partialName ) if ( fs . existsSync ( partialPath ) ) { partial = fs . readFileSync ( partialPath , 'utf8' ) } else { // or check if `partial + options.extension` is exists. // e.g. //   if `options.extension` equals ".html": //   the `{{> ./path/to/partial }}` will load //   `./path/to/partial.html`. if ( typeof options . extension === 'string' ) { partialPath = path . resolve ( templateDir , partialName + options . extension ) if ( fs . existsSync ( partialPath ) ) { partial = fs . readFileSync ( partialPath , 'utf8' ) } } // when `options.extension` is not a string or // `partialName + options.extension` does not exists. // try use `.mustache` extension to load `partial` file. if ( partial === null ) { partialPath = path . resolve ( templateDir , partialName + '.mustache' ) partial = fs . readFileSync ( partialPath , 'utf8' ) } } } partials [ partialName ] = partial loadPartials . call ( this , partial , partialPath ) } catch ( ex ) { this . emit ( 'error' , new PluginError ( 'gulp-mustache' , // use `ex.message` property instead of `partialPath`, // because `this.emit()` seems not a sync method. // also the `ex.message` property provide more details // about error information. 'Unable to load partial file: ' + ex . message ) ) } } } }
find and load partials not already in partials list from disk, recursively
find and load partials not already in partials list from disk recursively