1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-04 11:13:15 +00:00

Switched over to the new HTML class

This commit is contained in:
Jeremy Ruston 2012-02-06 10:57:55 +00:00
parent 7ac85ebbbb
commit 00774c1a48
3 changed files with 168 additions and 176 deletions

View File

@ -14,6 +14,7 @@ WikiStore uses the .cache member of tiddlers to store the following information:
"use strict";
var Tiddler = require("./Tiddler.js").Tiddler,
HTML = require("./HTML.js").HTML,
utils = require("./Utils.js");
/* Creates a new WikiStore object
@ -353,30 +354,30 @@ WikiStore.prototype.renderTiddler = function(targetType,title,templateTitle,opti
if(typeof templateTitle !== "string") {
templateTitle = title;
}
var stitcher = ((targetType === "text/html") && !options.noWrap && !this.disableHtmlWrapperNodes) ? utils.stitchElement : function(a,b,c) {return c.content;},
var noWrap = options.noWrap || this.disableHtmlWrapperNodes,
tiddler = this.getTiddler(title),
renderer = this.compileTiddler(templateTitle,targetType),
renditions = this.getCacheForTiddler(templateTitle,"renditions",function() {
return {};
});
}),
template,
content;
if(tiddler) {
if(title !== templateTitle) {
var template = this.getTiddler(templateTitle);
return stitcher("div",{
"data-tw-render-tiddler": title,
"data-tw-render-template": templateTitle
},{
content: renderer.render(tiddler,this)
});
template = this.getTiddler(templateTitle);
content = renderer.render(tiddler,this);
return noWrap ? content : HTML(HTML.elem("div",{
"data-tw-render-tiddler": title,
"data-tw-render-template": templateTitle
},[HTML.raw(content)]),targetType);
} else {
if(!renditions[targetType]) {
renditions[targetType] = renderer.render(tiddler,this);
}
return stitcher("div",{
"data-tw-render-tiddler": title
},{
content: renditions[targetType]
});
content = renditions[targetType];
return noWrap ? content : HTML(HTML.elem("div",{
"data-tw-render-tiddler": title
},[HTML.raw(content)]),targetType);
}
}
return null;

View File

@ -10,6 +10,7 @@ A container for the parse tree generated by parsing wikitext
"use strict";
var WikiTextRenderer = require("./WikiTextRenderer.js").WikiTextRenderer,
HTML = require("./HTML.js").HTML,
ArgParser = require("./ArgParser.js").ArgParser,
utils = require("./Utils.js");
@ -172,10 +173,10 @@ WikiTextParseTree.prototype.compileMacroCall = function(output,renderer,type,nod
// Add the wrapper node
var wrapperTag = macro.wrapperTag || "div";
if(type === "text/html" && !this.store.disableHtmlWrapperNodes) {
pushString(output,utils.stitchElement(wrapperTag,{
pushString(output,HTML(HTML.elem(wrapperTag,{
"data-tw-macro": name,
"data-tw-render-step": renderStepIndex
}));
})));
}
// Output the macro call
output.push({
@ -204,9 +205,7 @@ WikiTextParseTree.prototype.compileMacroCall = function(output,renderer,type,nod
WikiTextParseTree.prototype.compileElementHtml = function(output,renderer,element,options) {
options = options || {};
pushString(output,utils.stitchElement(element.type,element.attributes,{
selfClosing: options.selfClosing
}));
pushString(output,HTML(HTML.elem(element.type,element.attributes)));
if(!options.selfClosing) {
if(element.children) {
this.compileSubTreeHtml(output,renderer,element.children);
@ -277,119 +276,100 @@ WikiTextParseTree.prototype.compileSubTreePlain = function(output,renderer,tree)
// Render the parse tree to a debugging string of the specified MIME type
WikiTextParseTree.prototype.toString = function(type) {
var output = [],
htmlNodes = "a br hr table tr td th h1 h2 h3 h4 h5 h6 ul ol li dl dd dt blockquote pre img strong em u sup sub strike code span div".split(" "),
customTemplates = [
function(output,type,node) { // Text nodes
if(node.type === "text") {
output.push(utils.stitchElement("div",null,
{classes: ["treeNode","splitLabel"]}));
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "text"},{
content: node.type,
classes: ["splitLabelLeft"]
}));
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(node.value).replace(/\n/g,"<br>"),
classes: ["splitLabelRight"]
}));
output.push("</div>");
return true;
}
return false;
},
function(output,type,node) { // Macro nodes
if(node.type === "macro") {
output.push(utils.stitchElement("span",
{"data-tw-treenode-type": "macro"},{
content: utils.htmlEncode(node.name),
classes: ["treeNode","label"]
}));
for(var f in node.params) {
output.push(utils.stitchElement("span",null,{
classes: ["splitLabel"]
}));
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "param"},{
content: utils.htmlEncode(f),
classes: ["splitLabelLeft"]
}));
var v = node.params[f].value;
if(node.params[f].type === "string") {
v = '"' + utils.stringify(v) + '"';
} else if(node.params[f].type === "eval") {
v = "{{" + v + "}}";
}
output.push(utils.stitchElement("span",null,{
content: utils.htmlEncode(v),
classes: ["splitLabelRight"]
}));
output.push("</span>");
}
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>");
if(node.children) {
utils.renderObject(output,type,node.children,customTemplates);
}
return true;
}
return false;
},
function(output,type,node) { // HTML nodes
if(htmlNodes.indexOf(node.type) !== -1) {
output.push(utils.stitchElement("span",
{"data-tw-treenode-type": "html"},{
content: node.type,
classes: ["treeNode","label"]
}));
for(var f in node.attributes) {
output.push(utils.stitchElement("span",null,{
classes: ["treeNode"]
}));
var v = node.attributes[f];
if(typeof v === "string") {
v = '"' + utils.stringify(v) + '"';
} else if(v instanceof Array) {
v = v.join("; ");
}
if(typeof v === "object") {
output.push(utils.stitchElement("span",null,{
classes: ["label"],
content: utils.htmlEncode(f)
}));
utils.renderObject(output,type,v);
} else {
output.push(utils.stitchElement("span",null,{
classes: ["splitLabel"],
content: utils.stitchElement("span",null,{
classes: ["splitLabelLeft"],
content: utils.htmlEncode(f)
}) + utils.stitchElement("span",null,{
classes: ["splitLabelRight"],
content: utils.htmlEncode(v)
})
}));
}
output.push("</span>");
}
if(node.children) {
utils.renderObject(output,type,node.children,customTemplates);
}
return true;
} else {
return false;
}
var renderNode,
renderArray = function(tree) {
var children = [];
for(var t=0; t<tree.length; t++) {
children.push(HTML.elem("li",{
"class": ["nodeWikiText"]
},renderNode(tree[t])));
}
];
utils.renderObject(output,type,this.tree,customTemplates);
return output.join("");
return HTML.elem("ul",{
"class": ["treeWikiText"]
},children);
},
renderTextNode = function(node) {
return [HTML.splitLabel(
node.type,
[HTML.text(node.type)],
[HTML.raw(utils.htmlEncode(node.value).replace(/\n/g,"<br>"))],
["treeNode"]
)];
},
renderMacroNode = function(node) {
var params = [],
ret = [];
for(var p in node.params) {
var v = node.params[p].value;
if(node.params[p].type === "eval") {
v = "{{" + v + "}}";
}
params.push(HTML.splitLabel(
"param",
[HTML.text(p)],
[HTML.text(v)]
));
}
ret.push(HTML.splitLabel(
"macro",
[HTML.text(node.name)],
params,
["treeNode"]
));
ret.push(HTML.splitLabel(
"dependencies",
[HTML.text("Dependencies")],
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))],
["treeNode"]
));
if(node.children) {
ret.push(renderArray(node.children));
}
return ret;
},
renderHtmlNode = function(node) {
var attributes = [],
ret = [];
for(var a in node.attributes) {
var v = node.attributes[a];
if(typeof v === "string") {
v = v;
} else if(v instanceof Array) {
v = v.join("; ");
} else if(typeof v === "object") {
var o = [];
for(var n in v) {
o.push(n,":",v[n],";");
}
v = o.join("");
}
attributes.push(HTML.splitLabel(
"attribute",
[HTML.text(a)],
[HTML.text(v)]
));
}
ret.push(HTML.splitLabel(
"html",
[HTML.text(node.type)],
attributes,
["treeNode"]
));
if(node.children) {
ret.push(renderArray(node.children));
}
return ret;
};
renderNode = function(node) {
if(node.type === "text") {
return renderTextNode(node);
} else if(node.type === "macro") {
return renderMacroNode(node);
} else {
return renderHtmlNode(node);
}
};
return HTML(renderArray(this.tree),type);
};
exports.WikiTextParseTree = WikiTextParseTree;

View File

@ -9,7 +9,8 @@ An array of JavaScript functions that generate a specified representation of a p
/*jslint node: true */
"use strict";
var utils = require("./Utils.js");
var HTML = require("./HTML.js").HTML,
utils = require("./Utils.js");
var WikiTextRenderer = function() {
this.renderSteps = []; // Array of {step: n, dependencies: [],handler: function(tiddler,renderer,store,utils) {}}
@ -59,51 +60,61 @@ WikiTextRenderer.prototype.rerender = function(node,changes,tiddler,store,render
};
WikiTextRenderer.prototype.toString = function(type) {
var output = [],
stitchSplitLabel = function(name,value) {
output.push(utils.stitchElement("span",null,
{classes: ["treeNode","splitLabel"]}));
output.push(utils.stitchElement("span",null,{
content: name,
classes: ["splitLabelLeft"]
}));
output.push(utils.stitchElement("code",null,{
content: value,
classes: ["splitLabelRight"]
}));
output.push("</span>");
},
customTemplates = [
function(output,type,node) { // Rendering step
if(node.step !== undefined) {
output.push(utils.stitchElement("span",null,{
content: node.step.toString(),
classes: ["treeNode","label"]
}));
output.push(utils.stitchElement("span",null,{
content: node.type.toString(),
classes: ["treeNode","label"]
}));
stitchSplitLabel("dependencies",node.dependencies === null ? "*" : node.dependencies.join(", "));
if(node.macro) {
stitchSplitLabel("macro",utils.htmlEncode(node.macro.toString()));
}
if(node.params) {
stitchSplitLabel("params",utils.htmlEncode(node.params.toString()).replace(/\n/g,"<br>"));
}
if(node.content) {
stitchSplitLabel("content",utils.htmlEncode(node.content.toString()).replace(/\n/g,"<br>"));
}
if(node.handler) {
stitchSplitLabel("handler",utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"));
}
return true;
}
return false;
var renderNode,
renderArray = function(tree) {
var children = [];
for(var t=0; t<tree.length; t++) {
children.push(HTML.elem("li",{
"class": ["nodeWikiTextRenderer"]
},renderNode(tree[t])));
}
];
utils.renderObject(output,type,this.renderSteps,customTemplates);
return output.join("");
return HTML.elem("ul",{
"class": ["treeWikiTextRenderer"]
},children);
};
renderNode = function(node) {
var ret = [];
ret.push(HTML.splitLabel(
"rendererStep",
[HTML.text(node.step.toString())],
[HTML.text(node.type.toString())]
));
ret.push(HTML.splitLabel(
"dependencies",
[HTML.text("Dependencies")],
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))]
));
if(node.macro) {
ret.push(HTML.splitLabel(
"macro",
[HTML.text("macro")],
[HTML.text(node.macro)]
));
}
if(node.params) {
ret.push(HTML.splitLabel(
"params",
[HTML.text("params")],
[HTML.raw(utils.htmlEncode(node.params.toString()).replace(/\n/g,"<br>"))]
));
}
if(node.content) {
ret.push(HTML.splitLabel(
"content",
[HTML.text("content")],
[HTML.raw(utils.htmlEncode(node.content.toString()).replace(/\n/g,"<br>"))]
));
}
if(node.handler) {
ret.push(HTML.splitLabel(
"handler",
[HTML.text("handler")],
[HTML.raw(utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"))]
));
}
return ret;
};
return HTML(renderArray(this.renderSteps),type);
};
exports.WikiTextRenderer = WikiTextRenderer;