lib/hbs.js
function compileFile(locals, cb) {
    getSourceTemplate(function(err, source, template) {
      if (err) return cb(err);

      // Try to get the layout
      parseLayout(source, filename, function(err, layoutTemplates) {
        if (err) return cb(err);

        function renderIt(layoutTemplates) {
          if (self._options.beautify) {
            return render(template, locals, layoutTemplates, function(err, html) {
              if (err) return cb(err);
              loadBeautify();
              return cb(null, self.beautify(html, self.beautifyrc));
            });
          }
          return render(template, locals, layoutTemplates, cb);
        }

        // Determine which layout to use

        if (typeof options.layout !== 'undefined' && !options.layout) {
          // If options.layout is falsy, behave as if no layout should be used - suppress defaults
          renderIt(null);
        } else if (layoutTemplates) {
          // 1. Layout specified in template
          renderIt(layoutTemplates);
        } else if (typeof options.layout !== 'undefined' && options.layout) {
          // 2. Layout specified by options from render
          var layoutFile = self.layoutPath(filename, options.layout);
          self.cacheLayout(layoutFile, options.cache, function(err, layoutTemplates) {
            if (err) return cb(err);
            renderIt(layoutTemplates);
          });
        } else if (self.defaultLayoutTemplates) {
          // 3. Default layout specified when middleware was configured.
          renderIt(self.defaultLayoutTemplates);
        } else {
          // render without a template
          renderIt(null);
        }
      });
    });
  }
function compileFile(locals, cb) {
    getSourceTemplate(function(err, source, template) {
      if (err) return cb(err);

      // Try to get the layout
      parseLayout(source, filename, function(err, layoutTemplates) {
        if (err) return cb(err);

        function renderIt(layoutTemplates) {
          if (self._options.beautify) {
            return render(template, locals, layoutTemplates, function(err, html) {
              if (err) return cb(err);
              loadBeautify();
              return cb(null, self.beautify(html, self.beautifyrc));
            });
          }
          return render(template, locals, layoutTemplates, cb);
        }

        // Determine which layout to use

        if (typeof options.layout !== 'undefined' && !options.layout) {
          // If options.layout is falsy, behave as if no layout should be used - suppress defaults
          renderIt(null);
        } else if (layoutTemplates) {
          // 1. Layout specified in template
          renderIt(layoutTemplates);
        } else if (typeof options.layout !== 'undefined' && options.layout) {
          // 2. Layout specified by options from render
          var layoutFile = self.layoutPath(filename, options.layout);
          self.cacheLayout(layoutFile, options.cache, function(err, layoutTemplates) {
            if (err) return cb(err);
            renderIt(layoutTemplates);
          });
        } else if (self.defaultLayoutTemplates) {
          // 3. Default layout specified when middleware was configured.
          renderIt(self.defaultLayoutTemplates);
        } else {
          // render without a template
          renderIt(null);
        }
      });
    });
  }
function compileFile ( locals , cb ) { getSourceTemplate ( function ( err , source , template ) { if ( err ) return cb ( err ) ; // Try to get the layout parseLayout ( source , filename , function ( err , layoutTemplates ) { if ( err ) return cb ( err ) ; function renderIt ( layoutTemplates ) { if ( self . _options . beautify ) { return render ( template , locals , layoutTemplates , function ( err , html ) { if ( err ) return cb ( err ) ; loadBeautify ( ) ; return cb ( null , self . beautify ( html , self . beautifyrc ) ) ; } ) ; } return render ( template , locals , layoutTemplates , cb ) ; } // Determine which layout to use if ( typeof options . layout !== 'undefined' && ! options . layout ) { // If options.layout is falsy, behave as if no layout should be used - suppress defaults renderIt ( null ) ; } else if ( layoutTemplates ) { // 1. Layout specified in template renderIt ( layoutTemplates ) ; } else if ( typeof options . layout !== 'undefined' && options . layout ) { // 2. Layout specified by options from render var layoutFile = self . layoutPath ( filename , options . layout ) ; self . cacheLayout ( layoutFile , options . cache , function ( err , layoutTemplates ) { if ( err ) return cb ( err ) ; renderIt ( layoutTemplates ) ; } ) ; } else if ( self . defaultLayoutTemplates ) { // 3. Default layout specified when middleware was configured. renderIt ( self . defaultLayoutTemplates ) ; } else { // render without a template renderIt ( null ) ; } } ) ; } ) ; }
Compiles a file into a template and a layoutTemplate, then renders it above.
Compiles a file into a template and a layoutTemplate then renders it above .