lib/renderer.js
/**
 * A Handlebars rendering abstraction class. Made a constructor to allow
 * sub-classing and customization.
 *
 * @constructor
 * @param {Object} options
 */
A Handlebars rendering abstraction class. Made a constructor to allow
sub-classing and customization.

@constructor
@param {Object} options
A Handlebars rendering abstraction class . Made a constructor to allow sub - classing and customization . @constructor @param { Object } options
function Renderer(options) {
  if (!(this instanceof Renderer)) {
    return new Renderer(options);
  }
  if (options) {
    debug("creating koa-handlebars instance with options", options);
  } else {
    debug("creating koa-handlebars instance");
  }
  var o = this.options = extend({}, Renderer.defaults, options);
  debug("using %s as the root", chalk.grey(o.root));
  if (o.handlebars) {
    debug("using a custom handlebars instance");
    this.handlebars = o.handlebars;
  } else {
    this.handlebars = handlebars.create();
  }
  if (o.helpers) this.helper(o.helpers);
  if (o.partials) this.partial(o.partials);
  if (o.cache) {
    debug("caching enabled");
    this.cache = new Cache({ max: 100 });
  }
}
function Renderer ( options ) { if ( ! ( this instanceof Renderer ) ) { return new Renderer ( options ) ; } if ( options ) { debug ( "creating koa-handlebars instance with options" , options ) ; } else { debug ( "creating koa-handlebars instance" ) ; } var o = this . options = extend ( { } , Renderer . defaults , options ) ; debug ( "using %s as the root" , chalk . grey ( o . root ) ) ; if ( o . handlebars ) { debug ( "using a custom handlebars instance" ) ; this . handlebars = o . handlebars ; } else { this . handlebars = handlebars . create ( ) ; } if ( o . helpers ) this . helper ( o . helpers ) ; if ( o . partials ) this . partial ( o . partials ) ; if ( o . cache ) { debug ( "caching enabled" ) ; this . cache = new Cache ( { max : 100 } ) ; } }
A Handlebars rendering abstraction class.
A Handlebars rendering abstraction class .
// create complete options object (using defaults) // custom handlebars instance // register global helpers/partials // enabling caching (via lru-cache)