From 56e701b32619240ca328551ef3efe038b337ed06 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 30 Jan 2012 17:30:33 +0000 Subject: [PATCH] Switched stitchElement parameter from className to classes It's shorter, and looks better --- js/Utils.js | 30 +++++++++++++++--------------- js/WikiTextParseTree.js | 32 ++++++++++++++++---------------- js/WikiTextRenderer.js | 14 +++++++------- js/macros/link.js | 2 +- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/js/Utils.js b/js/Utils.js index ba1de52b5..308616ca7 100755 --- a/js/Utils.js +++ b/js/Utils.js @@ -246,7 +246,7 @@ utils.stringify = function(s) { // are processed to attr="name1:value1;name2:value2;" // The options include: // content: a string to include as content in the element (also generates closing tag) -// classNames: an array of classnames to apply to the element +// classes: an array of classnames to apply to the element // selfClosing: causes the element to be rendered with a trailing /, as in
// insertAfterAttributes: a string to insert after the attribute section of the element utils.stitchElement = function(element,attributes,options) { @@ -275,8 +275,8 @@ utils.stitchElement = function(element,attributes,options) { if(options.insertAfterAttributes) { output.push(options.insertAfterAttributes); } - if(options.classNames) { - output.push(" class='",options.classNames.join(" "),"'"); + if(options.classes) { + output.push(" class='",options.classes.join(" "),"'"); } output.push(">"); if("content" in options) { @@ -295,7 +295,7 @@ utils.stitchSlider = function(type,label,tooltip,body) { } var labelNode = utils.stitchElement("a",labelAttrs,{ content: label, - classNames: ["tw-slider-label"] + classes: ["tw-slider-label"] }), bodyNode = utils.stitchElement("div",{ style: { @@ -303,11 +303,11 @@ utils.stitchSlider = function(type,label,tooltip,body) { } },{ content: body, - classNames: ["tw-slider-body"] + classes: ["tw-slider-body"] }); return utils.stitchElement("div",null,{ content: labelNode + bodyNode, - classNames: ["tw-slider"] + classes: ["tw-slider"] }); } else if(type === "text/plain") { return label + "\n" + body; @@ -332,30 +332,30 @@ The custom template function should push the string rendering of the node to the utils.renderObject = function(output,type,node,customTemplates) { var renderNodeHtml, renderArrayHtml = function(output,tree) { - output.push(utils.stitchElement("ul",null,{classNames: ["treeArray"]})); + output.push(utils.stitchElement("ul",null,{classes: ["treeArray"]})); for(var t=0; t"); } output.push(""); }, renderFieldHtml = function(output,name,value) { - output.push(utils.stitchElement("li",null,{classNames: ["treeNodeField"]})); + output.push(utils.stitchElement("li",null,{classes: ["treeNodeField"]})); if(typeof value === "object") { output.push(utils.stitchElement("span",null,{ - classNames: ["label"], + classes: ["label"], content: utils.htmlEncode(name) })); renderNodeHtml(output,value); } else { output.push(utils.stitchElement("span",null,{ - classNames: ["splitLabel"], + classes: ["splitLabel"], content: utils.stitchElement("span",null,{ - classNames: ["splitLabelLeft"], + classes: ["splitLabelLeft"], content: utils.htmlEncode(name) }) + utils.stitchElement("span",null,{ - classNames: ["splitLabelRight"], + classes: ["splitLabelRight"], content: utils.htmlEncode(value) }) })); @@ -367,7 +367,7 @@ utils.renderObject = function(output,type,node,customTemplates) { renderArrayHtml(output,node); } else if (typeof node === "string") { output.push(utils.stitchElement("span",null,{ - classNames: ["treeNode","label"], + classes: ["treeNode","label"], content: utils.htmlEncode(node) })); } else { @@ -378,7 +378,7 @@ utils.renderObject = function(output,type,node,customTemplates) { } } if(!custom) { - output.push(utils.stitchElement("ul",null,{classNames: ["treeNode"]})); + output.push(utils.stitchElement("ul",null,{classes: ["treeNode"]})); for(var f in node) { renderFieldHtml(output,f,node[f]); } diff --git a/js/WikiTextParseTree.js b/js/WikiTextParseTree.js index 22eb2e320..2a23b99e9 100644 --- a/js/WikiTextParseTree.js +++ b/js/WikiTextParseTree.js @@ -288,14 +288,14 @@ WikiTextParseTree.prototype.toString = function(type) { function(output,type,node) { // Text nodes if(node.type === "text") { output.push(utils.stitchElement("div",null, - {classNames: ["treeNode","splitLabel"]})); + {classes: ["treeNode","splitLabel"]})); output.push(utils.stitchElement("span",{"data-tw-treenode-type": "text"},{ content: node.type, - classNames: ["splitLabelLeft"] + classes: ["splitLabelLeft"] })); output.push(utils.stitchElement("span",null,{ content: utils.htmlEncode(node.value).replace(/\n/g,"
"), - classNames: ["splitLabelRight"] + classes: ["splitLabelRight"] })); output.push(""); return true; @@ -307,15 +307,15 @@ WikiTextParseTree.prototype.toString = function(type) { output.push(utils.stitchElement("span", {"data-tw-treenode-type": "macro"},{ content: utils.htmlEncode(node.name), - classNames: ["treeNode","label"] + classes: ["treeNode","label"] })); for(var f in node.params) { output.push(utils.stitchElement("span",null,{ - classNames: ["splitLabel"] + classes: ["splitLabel"] })); output.push(utils.stitchElement("span",{"data-tw-treenode-type": "param"},{ content: utils.htmlEncode(f), - classNames: ["splitLabelLeft"] + classes: ["splitLabelLeft"] })); var v = node.params[f].value; if(node.params[f].type === "string") { @@ -325,19 +325,19 @@ WikiTextParseTree.prototype.toString = function(type) { } output.push(utils.stitchElement("span",null,{ content: utils.htmlEncode(v), - classNames: ["splitLabelRight"] + classes: ["splitLabelRight"] })); output.push(""); } output.push(utils.stitchElement("span",null, - {classNames: ["treeNode","splitLabel"]})); + {classes: ["treeNode","splitLabel"]})); output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{ content: "dependencies", - classNames: ["splitLabelLeft"] + classes: ["splitLabelLeft"] })); output.push(utils.stitchElement("span",null,{ content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")), - classNames: ["splitLabelRight"] + classes: ["splitLabelRight"] })); output.push(""); if(node.children) { @@ -352,11 +352,11 @@ WikiTextParseTree.prototype.toString = function(type) { output.push(utils.stitchElement("span", {"data-tw-treenode-type": "html"},{ content: node.type, - classNames: ["treeNode","label"] + classes: ["treeNode","label"] })); for(var f in node.attributes) { output.push(utils.stitchElement("span",null,{ - classNames: ["treeNode"] + classes: ["treeNode"] })); var v = node.attributes[f]; if(typeof v === "string") { @@ -366,18 +366,18 @@ WikiTextParseTree.prototype.toString = function(type) { } if(typeof v === "object") { output.push(utils.stitchElement("span",null,{ - classNames: ["label"], + classes: ["label"], content: utils.htmlEncode(f) })); utils.renderObject(output,type,v); } else { output.push(utils.stitchElement("span",null,{ - classNames: ["splitLabel"], + classes: ["splitLabel"], content: utils.stitchElement("span",null,{ - classNames: ["splitLabelLeft"], + classes: ["splitLabelLeft"], content: utils.htmlEncode(f) }) + utils.stitchElement("span",null,{ - classNames: ["splitLabelRight"], + classes: ["splitLabelRight"], content: utils.htmlEncode(v) }) })); diff --git a/js/WikiTextRenderer.js b/js/WikiTextRenderer.js index 2fceefd08..c4afef1c2 100644 --- a/js/WikiTextRenderer.js +++ b/js/WikiTextRenderer.js @@ -37,28 +37,28 @@ WikiTextRenderer.prototype.toString = function(type) { output.push(utils.stitchElement("span", {"data-tw-treenode-type": "renderStep"},{ content: node.step.toString(), - classNames: ["treeNode","label"] + classes: ["treeNode","label"] })); output.push(utils.stitchElement("span",null, - {classNames: ["treeNode","splitLabel"]})); + {classes: ["treeNode","splitLabel"]})); output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{ content: "dependencies", - classNames: ["splitLabelLeft"] + classes: ["splitLabelLeft"] })); output.push(utils.stitchElement("span",null,{ content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")), - classNames: ["splitLabelRight"] + classes: ["splitLabelRight"] })); output.push(""); output.push(utils.stitchElement("span",null, - {classNames: ["treeNode","splitLabel"]})); + {classes: ["treeNode","splitLabel"]})); output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepHandler"},{ content: "handler", - classNames: ["splitLabelLeft"] + classes: ["splitLabelLeft"] })); output.push(utils.stitchElement("code",null,{ content: utils.htmlEncode(node.handler.toString()).replace(/\n/g,"
"), - classNames: ["splitLabelRight"] + classes: ["splitLabelRight"] })); output.push(""); return true; diff --git a/js/macros/link.js b/js/macros/link.js index 39b3bd26f..4dc1892a0 100644 --- a/js/macros/link.js +++ b/js/macros/link.js @@ -22,7 +22,7 @@ exports.macro = { href: params.target },{ content: content, - classNames: store.adjustClassesForLink([],params.target) + classes: store.adjustClassesForLink([],params.target) }); } else if (type === "text/plain") { return content;