lib/template-manager.js
function compileTemplate(baseDir, filePath, type) {
    return new options.Promise((resolve, reject) => {
      let now  = timestamp();

      let name = filePath.substring(baseDir.length + 1).replace(/\\/g, '/');
      name = name.substring(0, name.indexOf('.'));

      // A cached template is only invalidated if the environment is something
      // other than `development` and the time-to-live has been exceeded.
      if (cache[type][name] &&
         (env !== 'development' || cache[type][name]._cached + expires > now)) {
        return resolve(cache[type][name]);
      }

      fs.readFile(filePath, 'utf-8', (error, contents) => {
        if (error) {
          return reject(error);
        }

        cache[type][name] = hbs.compile(contents.trim());

        // Decorate the cached function with private members. The underscore
        // is necessary to avoid conflict with function's name to prevent all
        // compiled templates from being named `ret` in the cache.
        cache[type][name]._name   = name;
        cache[type][name]._cached = timestamp();

        return resolve(cache[type][name]);
      });
    });
  }
function compileTemplate(baseDir, filePath, type) {
    return new options.Promise((resolve, reject) => {
      let now  = timestamp();

      let name = filePath.substring(baseDir.length + 1).replace(/\\/g, '/');
      name = name.substring(0, name.indexOf('.'));

      // A cached template is only invalidated if the environment is something
      // other than `development` and the time-to-live has been exceeded.
      if (cache[type][name] &&
         (env !== 'development' || cache[type][name]._cached + expires > now)) {
        return resolve(cache[type][name]);
      }

      fs.readFile(filePath, 'utf-8', (error, contents) => {
        if (error) {
          return reject(error);
        }

        cache[type][name] = hbs.compile(contents.trim());

        // Decorate the cached function with private members. The underscore
        // is necessary to avoid conflict with function's name to prevent all
        // compiled templates from being named `ret` in the cache.
        cache[type][name]._name   = name;
        cache[type][name]._cached = timestamp();

        return resolve(cache[type][name]);
      });
    });
  }
function compileTemplate ( baseDir , filePath , type ) { return new options . Promise ( ( resolve , reject ) => { let now = timestamp ( ) ; let name = filePath . substring ( baseDir . length + 1 ) . replace ( / \\ / g , '/' ) ; name = name . substring ( 0 , name . indexOf ( '.' ) ) ; // A cached template is only invalidated if the environment is something // other than `development` and the time-to-live has been exceeded. if ( cache [ type ] [ name ] && ( env !== 'development' || cache [ type ] [ name ] . _cached + expires > now ) ) { return resolve ( cache [ type ] [ name ] ) ; } fs . readFile ( filePath , 'utf-8' , ( error , contents ) => { if ( error ) { return reject ( error ) ; } cache [ type ] [ name ] = hbs . compile ( contents . trim ( ) ) ; // Decorate the cached function with private members. The underscore // is necessary to avoid conflict with function's name to prevent all // compiled templates from being named `ret` in the cache. cache [ type ] [ name ] . _name = name ; cache [ type ] [ name ] . _cached = timestamp ( ) ; return resolve ( cache [ type ] [ name ] ) ; } ) ; } ) ; }
Compiles and caches the template stored at the specified file path, if it
exists. Cached templates will be stored in the in-memory cache belonging
to the specified template type.
@param  {String} baseDir  The base directory of the templates
@param  {String} filePath The path of the template to compile
@param  {String} type     The type of template this is
@return {Promise.<Function>}
@public
Compiles and caches the template stored at the specified file path if it exists . Cached templates will be stored in the in - memory cache belonging to the specified template type .