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}
|
"with": {byName: true, type: "text", dependentAll: true}
|
||||||
},
|
},
|
||||||
execute: function() {
|
execute: function() {
|
||||||
var tiddler = this.store.getTiddler(this.tiddlerTitle),
|
var renderTitle = this.params.target,
|
||||||
renderTitle = this.params.target,
|
|
||||||
renderTemplate = this.params.template,
|
renderTemplate = this.params.template,
|
||||||
content,
|
content,
|
||||||
contentClone = [],
|
contentClone = [],
|
||||||
t,
|
t,
|
||||||
parents = this.parents.slice(0);
|
parents = this.parents.slice(0);
|
||||||
|
// If there's no render title specified then use the current tiddler title
|
||||||
if(typeof renderTitle !== "string") {
|
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") {
|
if(typeof renderTemplate !== "string") {
|
||||||
renderTemplate = renderTitle;
|
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) {
|
if("with" in this.params) {
|
||||||
// Parameterised transclusion
|
// Parameterised transclusion
|
||||||
var targetTiddler = this.store.getTiddler(renderTemplate),
|
var targetTiddler = this.store.getTiddler(renderTemplate),
|
||||||
@ -82,16 +86,18 @@ exports.macro = {
|
|||||||
var parseTree = this.store.parseTiddler(renderTemplate);
|
var parseTree = this.store.parseTiddler(renderTemplate);
|
||||||
content = parseTree ? parseTree.nodes : [];
|
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);
|
parents.push(renderTemplate);
|
||||||
|
// Clone the content
|
||||||
for(t=0; t<content.length; t++) {
|
for(t=0; t<content.length; t++) {
|
||||||
contentClone.push(content[t].clone());
|
contentClone.push(content[t].clone());
|
||||||
}
|
}
|
||||||
|
// Execute macros within the content
|
||||||
for(t=0; t<contentClone.length; t++) {
|
for(t=0; t<contentClone.length; t++) {
|
||||||
contentClone[t].execute(parents,this.store.getTiddler(renderTitle));
|
contentClone[t].execute(parents,this.store.getTiddler(renderTitle));
|
||||||
}
|
}
|
||||||
|
// Return the content
|
||||||
return contentClone;
|
return contentClone;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,35 +19,51 @@ exports.macro = {
|
|||||||
template: {byPos: 2, type: "text"}
|
template: {byPos: 2, type: "text"}
|
||||||
},
|
},
|
||||||
execute: function() {
|
execute: function() {
|
||||||
if(!this.tiddlerTitle) {
|
|
||||||
return Renderer.ErrorNode("Missing tiddler");
|
|
||||||
} else {
|
|
||||||
var tiddler = this.store.getTiddler(this.tiddlerTitle),
|
var tiddler = this.store.getTiddler(this.tiddlerTitle),
|
||||||
v = tiddler[this.params.field],
|
field = this.hasParameter("field") ? this.params.field : "title",
|
||||||
|
value,
|
||||||
content,
|
content,
|
||||||
t,
|
t,
|
||||||
contentClone = [],
|
contentClone = [],
|
||||||
parents = this.parents;
|
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) {
|
switch(this.params.format) {
|
||||||
case "link":
|
case "link":
|
||||||
var link = Renderer.MacroNode("link",
|
var link = Renderer.MacroNode("link",
|
||||||
{target: v},
|
{target: value},
|
||||||
[Renderer.TextNode(v)],
|
[Renderer.TextNode(value)],
|
||||||
this.store);
|
this.store);
|
||||||
link.execute(parents,tiddler);
|
link.execute(parents,tiddler);
|
||||||
return [link];
|
return [link];
|
||||||
case "wikified":
|
case "wikified":
|
||||||
if(this.params.field === "text") {
|
if(tiddler && this.params.field === "text") {
|
||||||
if(parents.indexOf(tiddler.title) === -1) {
|
if(parents.indexOf(tiddler.title) !== -1) {
|
||||||
content = this.store.parseTiddler(tiddler.title).nodes;
|
|
||||||
} else {
|
|
||||||
content = [Renderer.ErrorNode("Tiddler recursion error in <<view>> macro")];
|
content = [Renderer.ErrorNode("Tiddler recursion error in <<view>> macro")];
|
||||||
|
} else {
|
||||||
|
content = this.store.parseTiddler(tiddler.title).nodes;
|
||||||
}
|
}
|
||||||
parents = parents.slice(0);
|
parents = parents.slice(0);
|
||||||
parents.push(tiddler.title);
|
parents.push(tiddler.title);
|
||||||
} else {
|
} 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++) {
|
for(t=0; t<content.length; t++) {
|
||||||
contentClone.push(content[t].clone());
|
contentClone.push(content[t].clone());
|
||||||
@ -58,11 +74,13 @@ exports.macro = {
|
|||||||
return contentClone;
|
return contentClone;
|
||||||
case "date":
|
case "date":
|
||||||
var template = this.params.template || "DD MMM YYYY";
|
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"
|
default: // "text"
|
||||||
return [Renderer.TextNode(v)];
|
return [Renderer.TextNode(value)];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user