Code coverage report for lib/formatters/html.js

Statements: 68.75% (11 / 16)      Branches: 0% (0 / 2)      Functions: 66.67% (4 / 6)      Lines: 68.75% (11 / 16)      Ignored: none     

All files » lib/formatters/ » html.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 501                                   1   1                 1         1 1   1 1   1           1     1
var _ = require('lodash'),
  async = require('async'),
  bag = require('jazz'),
  fs = require('fs'),
  jazz = require('jazz'),
  p = require('path');
 
/**
 * Format health check results into HTML using Bootstrap CDN.
 *
 * @param {Object} results: an array of result objects containing:
 * - name: resource name
 * - status: ok or fail
 * - uri: the resource that was checked
 * - desc: result description, e.g. failure explanation
 * - duration: check response time in milliseconds
 * @return {String} a HTML string
 */
function format(results) {
 
  function _escape(data, cb) {
    if (typeof data === 'object') {
      data = JSON.stringify(data);
    }
    data = data.replace(/\r?\n/g, '<br/>');
    data = _.escape(data);
    cb(data);
  }
 
  var text = fs.readFileSync(p.join(__dirname, '../../views/html.jazz')).toString(),
    template = jazz.compile(text),
    params = { results: results, escape: _escape },
    applied;
 
  async.whilst(
    function () { return applied === undefined; },
    function (cb) {
      template.process(params, function (result) {
        applied = result;
      });
      setTimeout(cb, 1);
    },
    function (err) {
    }
  );
 
  return applied;
}
 
exports.format = format;