mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-24 02:27:19 +00:00
Improving the handling of missing tiddlers
On the way to being able to edit tiddlers
This commit is contained in:
parent
cbb8ee3bb0
commit
cd0f8ebb52
@ -53,20 +53,24 @@ exports.macro = {
|
||||
"with": {byName: true, type: "text", dependentAll: true}
|
||||
},
|
||||
execute: function() {
|
||||
var tiddler = this.store.getTiddler(this.tiddlerTitle),
|
||||
renderTitle = this.params.target,
|
||||
var renderTitle = this.params.target,
|
||||
renderTemplate = this.params.template,
|
||||
content,
|
||||
contentClone = [],
|
||||
t,
|
||||
parents = this.parents.slice(0);
|
||||
// If there's no render title specified then use the current tiddler title
|
||||
if(typeof renderTitle !== "string") {
|
||||
renderTitle = tiddler.title;
|
||||
renderTitle = this.tiddlerTitle;
|
||||
}
|
||||
// If there's no template specified then use the target tiddler title
|
||||
if(typeof renderTemplate !== "string") {
|
||||
renderTemplate = renderTitle;
|
||||
}
|
||||
if(parents.indexOf(renderTemplate) === -1) {
|
||||
// Check for recursion
|
||||
if(parents.indexOf(renderTemplate) !== -1) {
|
||||
content = [Renderer.ErrorNode("Tiddler recursion error in <<tiddler>> macro")];
|
||||
} else {
|
||||
if("with" in this.params) {
|
||||
// Parameterised transclusion
|
||||
var targetTiddler = this.store.getTiddler(renderTemplate),
|
||||
@ -82,16 +86,18 @@ exports.macro = {
|
||||
var parseTree = this.store.parseTiddler(renderTemplate);
|
||||
content = parseTree ? parseTree.nodes : [];
|
||||
}
|
||||
} else {
|
||||
content = [Renderer.ErrorNode("Tiddler recursion error in <<tiddler>> macro")];
|
||||
}
|
||||
// Update the stack of tiddler titles for recursion detection
|
||||
parents.push(renderTemplate);
|
||||
// Clone the content
|
||||
for(t=0; t<content.length; t++) {
|
||||
contentClone.push(content[t].clone());
|
||||
}
|
||||
// Execute macros within the content
|
||||
for(t=0; t<contentClone.length; t++) {
|
||||
contentClone[t].execute(parents,this.store.getTiddler(renderTitle));
|
||||
}
|
||||
// Return the content
|
||||
return contentClone;
|
||||
}
|
||||
};
|
||||
|
@ -19,35 +19,51 @@ exports.macro = {
|
||||
template: {byPos: 2, type: "text"}
|
||||
},
|
||||
execute: function() {
|
||||
if(!this.tiddlerTitle) {
|
||||
return Renderer.ErrorNode("Missing tiddler");
|
||||
} else {
|
||||
var tiddler = this.store.getTiddler(this.tiddlerTitle),
|
||||
v = tiddler[this.params.field],
|
||||
field = this.hasParameter("field") ? this.params.field : "title",
|
||||
value,
|
||||
content,
|
||||
t,
|
||||
contentClone = [],
|
||||
parents = this.parents;
|
||||
if(v !== undefined) {
|
||||
if(tiddler) {
|
||||
value = tiddler[field];
|
||||
} else {
|
||||
switch(field) {
|
||||
case "text":
|
||||
value = "The tiddler '" + this.tiddlerTitle + "' does not exist";
|
||||
break;
|
||||
case "title":
|
||||
value = this.tiddlerTitle;
|
||||
break;
|
||||
case "modified":
|
||||
case "created":
|
||||
value = new Date();
|
||||
break;
|
||||
default:
|
||||
value = "Missing tiddler '" + this.tiddlerTitle + "'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch(this.params.format) {
|
||||
case "link":
|
||||
var link = Renderer.MacroNode("link",
|
||||
{target: v},
|
||||
[Renderer.TextNode(v)],
|
||||
{target: value},
|
||||
[Renderer.TextNode(value)],
|
||||
this.store);
|
||||
link.execute(parents,tiddler);
|
||||
return [link];
|
||||
case "wikified":
|
||||
if(this.params.field === "text") {
|
||||
if(parents.indexOf(tiddler.title) === -1) {
|
||||
content = this.store.parseTiddler(tiddler.title).nodes;
|
||||
} else {
|
||||
if(tiddler && this.params.field === "text") {
|
||||
if(parents.indexOf(tiddler.title) !== -1) {
|
||||
content = [Renderer.ErrorNode("Tiddler recursion error in <<view>> macro")];
|
||||
} else {
|
||||
content = this.store.parseTiddler(tiddler.title).nodes;
|
||||
}
|
||||
parents = parents.slice(0);
|
||||
parents.push(tiddler.title);
|
||||
} else {
|
||||
content = this.store.parseText("text/x-tiddlywiki",v).nodes;
|
||||
content = this.store.parseText("text/x-tiddlywiki",value).nodes;
|
||||
}
|
||||
for(t=0; t<content.length; t++) {
|
||||
contentClone.push(content[t].clone());
|
||||
@ -58,11 +74,13 @@ exports.macro = {
|
||||
return contentClone;
|
||||
case "date":
|
||||
var template = this.params.template || "DD MMM YYYY";
|
||||
return [Renderer.TextNode(utils.formatDateString(v,template))];
|
||||
if(value === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
return [Renderer.TextNode(utils.formatDateString(value,template))];
|
||||
}
|
||||
default: // "text"
|
||||
return [Renderer.TextNode(v)];
|
||||
}
|
||||
}
|
||||
return [Renderer.TextNode(value)];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user