lib/compile-render.js
function compileRender(templateSource, data, block) {
  const hash = md5(templateSource);

  return Promise.try(() => {
    const cached = compileRenderCache.get(hash);
    if (cached) {
      compileRenderCache.ttl(hash);
      return cached;
    }

    const templateFunction = precompile(templateSource, {})
      .then(code => evaluate(code));

    compileRenderCache.set(hash, templateFunction);
    return templateFunction;
  }).then((templateFunction) => {
    if (block) {
      templateFunction = templateFunction.blocks && templateFunction.blocks[block];
    }
    if (!templateFunction) {
      return '';
    }

    return runtime(Benchpress.helpers, data, templateFunction);
  }).catch((err) => {
    err.message = `Render failed for template ${templateSource.slice(0, 20)}:\n ${err.message}`;
    err.stack = `Render failed for template ${templateSource.slice(0, 20)}:\n ${err.stack}`;

    throw err;
  });
}
function compileRender(templateSource, data, block) {
  const hash = md5(templateSource);

  return Promise.try(() => {
    const cached = compileRenderCache.get(hash);
    if (cached) {
      compileRenderCache.ttl(hash);
      return cached;
    }

    const templateFunction = precompile(templateSource, {})
      .then(code => evaluate(code));

    compileRenderCache.set(hash, templateFunction);
    return templateFunction;
  }).then((templateFunction) => {
    if (block) {
      templateFunction = templateFunction.blocks && templateFunction.blocks[block];
    }
    if (!templateFunction) {
      return '';
    }

    return runtime(Benchpress.helpers, data, templateFunction);
  }).catch((err) => {
    err.message = `Render failed for template ${templateSource.slice(0, 20)}:\n ${err.message}`;
    err.stack = `Render failed for template ${templateSource.slice(0, 20)}:\n ${err.stack}`;

    throw err;
  });
}
function compileRender ( templateSource , data , block ) { const hash = md5 ( templateSource ) ; return Promise . try ( ( ) => { const cached = compileRenderCache . get ( hash ) ; if ( cached ) { compileRenderCache . ttl ( hash ) ; return cached ; } const templateFunction = precompile ( templateSource , { } ) . then ( code => evaluate ( code ) ) ; compileRenderCache . set ( hash , templateFunction ) ; return templateFunction ; } ) . then ( ( templateFunction ) => { if ( block ) { templateFunction = templateFunction . blocks && templateFunction . blocks [ block ] ; } if ( ! templateFunction ) { return '' ; } return runtime ( Benchpress . helpers , data , templateFunction ) ; } ) . catch ( ( err ) => { err . message = ` ${ templateSource . slice ( 0 , 20 ) } \n ${ err . message } ` ; err . stack = ` ${ templateSource . slice ( 0 , 20 ) } \n ${ err . stack } ` ; throw err ; } ) ; }
Compile a template and render it
Automatically caches template function based on hash of input template
@param {string} templateSource
@param {any} data
@param {string} [block]
@returns {Promise<string>} - rendered output
Compile a template and render it Automatically caches template function based on hash of input template