1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-24 18:47:20 +00:00
TiddlyWiki5/js/WikiTextRenderer.js
Jeremy Ruston 56e701b326 Switched stitchElement parameter from className to classes
It's shorter, and looks better
2012-01-30 17:30:33 +00:00

76 lines
2.2 KiB
JavaScript

/*\
title: js/WikiTextRenderer.js
An array of JavaScript functions that generate a specified representation of a parse tree
\*/
(function(){
/*jslint node: true */
"use strict";
var utils = require("./Utils.js");
var WikiTextRenderer = function() {
this.renderSteps = []; // Array of {step: n, dependencies: [],handler: function(tiddler,renderer,store,utils) {}}
};
WikiTextRenderer.prototype.addRenderStep = function(renderStep) {
this.renderSteps.push(renderStep);
return this.renderSteps.length - 1;
};
WikiTextRenderer.prototype.render = function(tiddler,store,renderStep) {
renderStep = renderStep || 0;
if(renderStep < this.renderSteps.length) {
return this.renderSteps[renderStep].handler(tiddler,this,store,utils);
} else {
return null;
}
};
WikiTextRenderer.prototype.toString = function(type) {
var output = [],
customTemplates = [
function(output,type,node) { // Rendering step
if(node.step !== undefined) {
output.push(utils.stitchElement("span",
{"data-tw-treenode-type": "renderStep"},{
content: node.step.toString(),
classes: ["treeNode","label"]
}));
output.push(utils.stitchElement("span",null,
{classes: ["treeNode","splitLabel"]}));
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{
content: "dependencies",
classes: ["splitLabelLeft"]
}));
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")),
classes: ["splitLabelRight"]
}));
output.push("</span>");
output.push(utils.stitchElement("span",null,
{classes: ["treeNode","splitLabel"]}));
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepHandler"},{
content: "handler",
classes: ["splitLabelLeft"]
}));
output.push(utils.stitchElement("code",null,{
content: utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"),
classes: ["splitLabelRight"]
}));
output.push("</span>");
return true;
}
return false;
}
];
utils.renderObject(output,type,this.renderSteps,customTemplates);
return output.join("");
};
exports.WikiTextRenderer = WikiTextRenderer;
})();