PageRenderTime 24ms CodeModel.GetById 19ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/documentation/example/literate.js

https://bitbucket.org/darrint/qc.js/
JavaScript | 50 lines | 41 code | 5 blank | 4 comment | 5 complexity | 207df171f36e2f501f5517b995d82685 MD5 | raw file
 1// A specialized listener which pokes results into a div with jquery.
 2function LiterateListener(jqDest) {
 3    this.jqDest = jqDest;
 4}
 5
 6LiterateListener.prototype.noteResult = function(result) {
 7    var status_string = result.status + ": " + result.name;
 8    this.log(status_string);
 9    this.logResult(result);
10    if (result.status == "pass") {
11	// do nothing.
12    } else {
13	this.jqDest.removeClass("green");
14	this.jqDest.addClass("red");
15    }
16    if (result.status == "fail") {
17        this.log("Failed case:");
18        this.log(result.failedCase.toString());
19    }
20};
21
22LiterateListener.prototype.done = function(result) {
23    this.log('done.');
24};
25
26LiterateListener.prototype.log = function(text) {
27    this.jqDest.append($('<span>' + text + '</span>'));
28    this.jqDest.append($('<br/>'));
29};
30
31LiterateListener.prototype.logResult = function(result) {
32    this.log("passes: " + result.stats.pass);
33    this.log("invalid: " + result.stats.invalid);
34}
35// Given a jquery identifier, run the code in the element and display
36// results in an helpful manner near the code.
37function literateRun(id) {
38    resetProps();
39    eval($(id).text());
40    var dest = $(id).after("<div>").next();
41    dest.addClass("test-result");
42    dest.addClass("green");
43    runAllProps(new Config(100, 1000), new LiterateListener(dest));
44}
45
46function runAllLiterate() {
47    $(".runme").each(function () {
48	    literateRun(this);
49	});
50}