{"size": 1767, "ext": "js", "max_stars_repo_path": "lib/reporters/HTMLReporter.js", "max_stars_repo_name": "arian/CoverJS", "max_stars_repo_stars_event_min_datetime": "2015-01-03T15:12:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T13:06:02.000Z", "max_issues_repo_path": "lib/reporters/HTMLReporter.js", "max_issues_repo_name": "arian/CoverJS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/reporters/HTMLReporter.js", "max_forks_repo_name": "arian/CoverJS", "max_forks_repo_forks_event_min_datetime": "2015-01-09T07:48:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-21T09:59:40.000Z"}
{"max_stars_count": 27, "max_issues_count": null, "max_forks_count": 4, "avg_line_length": 22.3670886076, "max_line_length": 94, "alphanum_fraction": 0.6276174307}
"use strict";

var Reporter = require('./Reporter');
var prime    = require('prime');

var HTMLReporter = prime({

	inherits: Reporter,

	constructor: function(object){
		HTMLReporter.parent.constructor(object);

		// TODO would be cool to use some nicer templating solution for this
		this.head = '' +
			'<!DOCTYPE html>\n' +
			'<html>\n<head>\n' +
			'<meta charset="utf-8">\n' +
			'<title>Coverate Results</title>\n' +
			'<style>\n' +
			'	.error { background: #F8D5D8 }\n' +
			'	.count { font-weight: bold; border-radius: 3px }\n' +
			'	.pass .count { background: #BFFFBF;}' +
			'	.error .count { background: #F8D5D8; color: red}' +
			'</style>\n' +
			'</head>\n<body>\n';

		this.tail = '\n</body>\n</html>';

	},

	report: function(){

		var result = this.head;

		for (var file in this.object){
			var fileReporter = new HTMLFileReporter(this.object[file]);

			var fileReport = fileReporter.report();
			var percentage = fileReporter.pass / fileReporter.total * 100;

			this.error += fileReporter.error;
			this.pass  += fileReporter.pass;
			this.total += fileReporter.total;

			result += '<h1>' + file + ' (' + Math.round(percentage) + '%)</h1>\n\n';
			result += '<pre>' + fileReport + '</pre>';
		}

		return result + this.tail;

	}

});

var HTMLFileReporter = prime({

	inherits: Reporter.FileReporter,

	constructor: function(object){

		var open  = '<span class="{class}" data-count="{count}"><span class="count">{count}</span>';
		var close = '</span>';

		HTMLFileReporter.parent.constructor(object, open, close);

	},

	generateOpen: function(count){
		return this.substitute(this.open, {
			'count': count,
			'class': count ? 'pass' : 'error'
		});
	}

});

HTMLReporter.FileReporter = HTMLFileReporter;
module.exports = HTMLReporter;
