1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 02:50:27 +00:00

Improvements to tree dumping

This commit is contained in:
Jeremy Ruston 2012-01-21 14:00:09 +00:00
parent 78c21d6ff8
commit b96f0c1bd6
3 changed files with 75 additions and 95 deletions

View File

@ -313,7 +313,7 @@ utils.renderObject = function(output,type,node,customTemplates) {
output.push(utils.stitchElement("li",null,{classNames: ["treeNodeField"]}));
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(name),
classNames: ["treeNodeFieldName"]
classNames: (typeof value === "object") ? ["label"] : ["splitLabel","splitLabelLeft"]
}));
if (value instanceof Array) {
renderArrayHtml(output,value);
@ -322,7 +322,7 @@ utils.renderObject = function(output,type,node,customTemplates) {
} else {
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(value),
classNames: ["treeNodeFieldValue"]
classNames: ["splitLabelRight"]
}));
}
output.push("</li>")
@ -331,7 +331,6 @@ utils.renderObject = function(output,type,node,customTemplates) {
if(node instanceof Array) {
renderArrayHtml(output,node);
} else {
output.push(utils.stitchElement("ul",null,{classNames: ["treeNode"]}));
var custom = false;
for(var t=0; t<customTemplates.length; t++) {
if(!custom && customTemplates[t](output,type,node)) {
@ -339,11 +338,12 @@ utils.renderObject = function(output,type,node,customTemplates) {
}
}
if(!custom) {
output.push(utils.stitchElement("ul",null,{classNames: ["treeNode"]}));
for(var f in node) {
renderFieldHtml(output,f,node[f]);
}
output.push("</ul>");
}
output.push("</ul>");
}
};
if(type === "text/html") {

View File

@ -257,28 +257,35 @@ WikiTextParseTree.prototype.toString = function(type) {
customTemplates = [
function(output,type,node) { // Text nodes
if(node.type === "text") {
output.push(utils.stitchElement("span",null,{
output.push(utils.stitchElement("div",null,
{classNames: ["treeNode","splitLabel"]}));
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "text"},{
content: node.type,
classNames: ["treeNodeTypeText"]
classNames: ["splitLabelLeft"]
}));
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(node.value).replace(/\n/g,"<br>"),
classNames: ["treeNodeFieldValue"]
classNames: ["splitLabelRight"]
}));
output.push("</div>");
return true;
}
return false;
},
function(output,type,node) { // Macro nodes
if(node.type === "macro") {
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(node.name),
classNames: ["treeNodeTypeMacro"]
output.push(utils.stitchElement("span",
{"data-tw-treenode-type": "macro"},{
content: utils.htmlEncode(node.name),
classNames: ["treeNode","label"]
}));
for(var f in node.params) {
output.push(utils.stitchElement("span",null,{
classNames: ["splitLabel"]
}));
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "param"},{
content: utils.htmlEncode(f),
classNames: ["treeNodeTypeParam"]
classNames: ["splitLabelLeft"]
}));
var v = node.params[f].value;
if(node.params[f].type === "string") {
@ -288,28 +295,34 @@ WikiTextParseTree.prototype.toString = function(type) {
}
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(v),
classNames: ["treeNodeFieldValue"]
classNames: ["splitLabelRight"]
}));
output.push("</span>");
}
if(node.children) {
utils.renderObject(output,type,node.children,customTemplates);
}
output.push("</span>");
return true;
}
return false;
},
function(output,type,node) { // HTML nodes
if(htmlNodes.indexOf(node.type) !== -1) {
output.push(utils.stitchElement("span",null,{
output.push(utils.stitchElement("span",
{"data-tw-treenode-type": "html"},{
content: node.type,
classNames: ["treeNodeTypeHtml"]
classNames: ["treeNode","label"]
}));
for(var f in node.attributes) {
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(f),
classNames: ["treeNodeType"]
output.push(utils.string("span",null,{
classNames: ["treeNode"]
}));
var v = node.attributes[f];
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(f),
classNames: (typeof v === "object") ? ["label"] : ["splitLabel","splitLabelLeft"]
}));
if(typeof v === "string") {
v = utils.stringify(v);
} else if(v instanceof Array) {
@ -320,7 +333,7 @@ WikiTextParseTree.prototype.toString = function(type) {
} else {
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(v),
classNames: ["treeNodeFieldValue"]
classNames: ["splitLabelRight"]
}));
}
}

View File

@ -95,97 +95,64 @@ a.tw-tiddlylink-missing {
font-style: italic;
}
.label {
text-transform: uppercase;
font-weight: bold;
font-size: 9.5px;
margin-right: 5px;
padding: 3px 5px 3px;
border-radius: 3px;
background-color: #cca;
}
.splitLabel {
font-size: 9.5px;
margin-right: 5px;
}
.splitLabelLeft {
text-transform: uppercase;
font-weight: bold;
padding: 3px 1px 3px 5px;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
background-color: #ccc;
}
.splitLabelRight {
padding: 3px 5px 3px 1px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
background-color: #eee;
}
.treeArray {
padding: 2px 4px 3px;
list-style-type: none;
}
.treeArrayMember {
padding: 2px 4px 3px;
margin-top: 3px;
}
.treeNodeType {
text-transform: uppercase;
padding: 3px 5px 3px;
background-color: #46A546;
color: #fff;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
font-size: 9.5px;
font-weight: bold;
.treeNode {
list-style-type: none;
}
.treeNodeTypeText {
text-transform: uppercase;
padding: 3px 5px 3px;
background-color: #4646a5;
color: #fff;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
font-size: 9.5px;
font-weight: bold;
list-style-type: none;
}
.treeNodeTypeMacro {
text-transform: uppercase;
padding: 3px 5px 3px;
margin-right: 3px;
background-color: #46A546;
color: #fff;
border-radius: 3px;
font-size: 9.5px;
font-weight: bold;
list-style-type: none;
}
.treeNodeTypeParam {
padding: 3px 5px 3px;
.splitLabelLeft[data-tw-treenode-type='text'] {
background-color: #62CFFC;
color: #fff;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
font-size: 9.5px;
font-weight: bold;
list-style-type: none;
}
.treeNodeTypeHtml {
text-transform: uppercase;
padding: 3px 5px 3px;
.label[data-tw-treenode-type='macro'] {
background-color: #46A546;
color: #fff;
}
.splitLabelLeft[data-tw-treenode-type='param'] {
background-color: #85e585;
color: #fff;
}
.label[data-tw-treenode-type='html'] {
background-color: #F89406;
color: #fff;
border-radius: 3px;
font-size: 9.5px;
font-weight: bold;
list-style-type: none;
}
.treeNodeField {
}
.treeNodeFieldName {
margin-right: 0;
padding: 3px 5px 3px;
background-color: #dedede;
color: #444;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
font-size: 10.5px;
font-weight: bold;
}
.treeNodeFieldValue {
margin-left: 0;
margin-right: 3px;
padding: 3px 5px 3px 3px;
background-color: #eee;
color: #000;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
font-size: 10.5px;
font-weight: bold;
}