/*\ title: $:/plugins/tiddlywiki/railroad/components.js type: application/javascript module-type: library Components of a railroad diagram. \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; var railroad = require("$:/plugins/tiddlywiki/railroad/railroad-diagrams.js"); /////////////////////////// Base component var Component = function() { this.type = "Component"; }; // Set up a leaf component Component.prototype.initialiseLeaf = function(type,text) { this.type = type; this.text = text; }; // Set up a component with a single child Component.prototype.initialiseWithChild = function(type,content) { this.type = type; this.child = toSingleChild(content); }; // Set up a component with an array of children Component.prototype.initialiseWithChildren = function(type,content) { this.type = type; // Force the content to be an array this.children = $tw.utils.isArray(content) ? content : [content]; } // Return an array of the SVG strings of an array of children Component.prototype.getSvgOfChildren = function() { return this.children.map(function(child) { return child.toSvg(); }); } Component.prototype.toSvg = function() { return ""; } Component.prototype.debug = function(output,indent) { output.push(indent); output.push(this.type); // Add the text of a leaf component if(this.text && this.text !== "") { output.push(": "); output.push(this.text); } // Flag the normal route if(this.normal !== undefined) { if(this.normal === true) { output.push(" (normal)"); } else if(this.normal !== false) { output.push(" (normal: "); output.push(this.normal); output.push(")"); } } output.push("\n"); var contentIndent = indent + " "; // Add the one child if(this.child) { this.child.debug(output,contentIndent); } // Add the array of children if(this.children) { this.debugArray(this.children,output,contentIndent); } // Add the separator if there is one if(this.separator) { output.push(indent); output.push("(separator)\n"); this.separator.debug(output,contentIndent); } }; Component.prototype.debugArray = function(array,output,indent) { for(var i=0; i