mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Update the tiddler and list macros to allow the template to be specified in the body of the macro
This commit is contained in:
parent
5fd3000838
commit
97f6314dbb
@ -20,9 +20,7 @@ exports.info = {
|
|||||||
filter: {byName: true, type: "filter"},
|
filter: {byName: true, type: "filter"},
|
||||||
history: {byName: true, type: "tiddler"},
|
history: {byName: true, type: "tiddler"},
|
||||||
template: {byName: true, type: "tiddler"},
|
template: {byName: true, type: "tiddler"},
|
||||||
templateText: {byName: true, type: "text"},
|
|
||||||
editTemplate: {byName: true, type: "tiddler"},
|
editTemplate: {byName: true, type: "tiddler"},
|
||||||
editTemplateText: {byName: true, type: "text"},
|
|
||||||
emptyMessage: {byName: true, type: "text"},
|
emptyMessage: {byName: true, type: "text"},
|
||||||
listviewTiddler: {byName: true, type: "tiddler"},
|
listviewTiddler: {byName: true, type: "tiddler"},
|
||||||
listview: {byName: true, type: "text"},
|
listview: {byName: true, type: "text"},
|
||||||
@ -145,28 +143,32 @@ Create the tiddler macro needed to represent a given tiddler
|
|||||||
exports.createListElementMacro = function(title) {
|
exports.createListElementMacro = function(title) {
|
||||||
// Check if the tiddler is a draft
|
// Check if the tiddler is a draft
|
||||||
var tiddler = this.wiki.getTiddler(title),
|
var tiddler = this.wiki.getTiddler(title),
|
||||||
draft = tiddler ? tiddler.hasField("draft.of") : false;
|
isDraft = tiddler ? tiddler.hasField("draft.of") : false;
|
||||||
// Figure out the template to use
|
// Figure out the template to use
|
||||||
var template = this.params.template,
|
var template = this.params.template,
|
||||||
templateText = this.params.templateText;
|
templateTree = undefined;
|
||||||
if(draft && this.hasParameter("editTemplate")) {
|
if(isDraft && this.hasParameter("editTemplate")) {
|
||||||
template = this.params.editTemplate;
|
template = this.params.editTemplate;
|
||||||
}
|
}
|
||||||
if(draft && this.hasParameter("editTemplateText")) {
|
// Check for not having a template
|
||||||
template = this.params.editTemplateText;
|
if(!template) {
|
||||||
|
if(this.content.length > 0) {
|
||||||
|
// Use our content as the template
|
||||||
|
templateTree = this.content;
|
||||||
|
} else {
|
||||||
|
// Use default content
|
||||||
|
var defaultTemplate = "<<view title link>>";
|
||||||
|
templateTree = this.wiki.parseText("text/vnd.tiddlywiki",defaultTemplate).tree;
|
||||||
}
|
}
|
||||||
// Check for no template specified
|
|
||||||
if(!template && !templateText) {
|
|
||||||
templateText = "<<view title link>>";
|
|
||||||
}
|
}
|
||||||
// Create the tiddler macro
|
// Create the tiddler macro
|
||||||
return $tw.Tree.Macro("tiddler",{
|
return $tw.Tree.Macro("tiddler",{
|
||||||
srcParams: {
|
srcParams: {
|
||||||
target: title,
|
target: title,
|
||||||
template: template,
|
template: template
|
||||||
templateText: templateText
|
|
||||||
},
|
},
|
||||||
wiki: this.wiki
|
wiki: this.wiki,
|
||||||
|
content: templateTree
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ exports.info = {
|
|||||||
target: {byName: "default", type: "tiddler"},
|
target: {byName: "default", type: "tiddler"},
|
||||||
targetVia: {byName: true, type: "tiddler"},
|
targetVia: {byName: true, type: "tiddler"},
|
||||||
template: {byName: true, type: "tiddler"},
|
template: {byName: true, type: "tiddler"},
|
||||||
templateText: {byName: true, type: "text"},
|
|
||||||
"with": {byName: true, type: "text", dependentAll: true}
|
"with": {byName: true, type: "text", dependentAll: true}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -98,8 +97,8 @@ exports.executeMacro = function() {
|
|||||||
renderTitle = this.tiddlerTitle;
|
renderTitle = this.tiddlerTitle;
|
||||||
}
|
}
|
||||||
// Get the render tree for the template
|
// Get the render tree for the template
|
||||||
if(this.hasParameter("templateText")) {
|
if(this.content.length > 0) {
|
||||||
renderTemplateTree = this.wiki.parseText("text/vnd.tiddlywiki",this.params.templateText).tree;
|
renderTemplateTree = this.content;
|
||||||
} else {
|
} else {
|
||||||
if(this.hasParameter("template")) {
|
if(this.hasParameter("template")) {
|
||||||
renderTemplateTitle = this.params.template;
|
renderTemplateTitle = this.params.template;
|
||||||
|
@ -34,7 +34,7 @@ exports.parse = function(match,isBlock) {
|
|||||||
match = regExp.exec(this.source);
|
match = regExp.exec(this.source);
|
||||||
if(match && match.index === this.pos) {
|
if(match && match.index === this.pos) {
|
||||||
this.pos = match.index + match[0].length;
|
this.pos = match.index + match[0].length;
|
||||||
var macro, params = {};
|
var macro, params = {}, parseTree;
|
||||||
// Check if it is a single tiddler
|
// Check if it is a single tiddler
|
||||||
if(match[1]) {
|
if(match[1]) {
|
||||||
macro = "tiddler";
|
macro = "tiddler";
|
||||||
@ -48,11 +48,12 @@ exports.parse = function(match,isBlock) {
|
|||||||
params.template = match[3];
|
params.template = match[3];
|
||||||
}
|
}
|
||||||
if(match[4]) {
|
if(match[4]) {
|
||||||
params.templateText = match[4];
|
parseTree = this.wiki.parseText("text/vnd.tiddlywiki",match[4]).tree;
|
||||||
}
|
}
|
||||||
return [$tw.Tree.Macro(macro,{
|
return [$tw.Tree.Macro(macro,{
|
||||||
srcParams: params,
|
srcParams: params,
|
||||||
wiki: this.wiki
|
wiki: this.wiki,
|
||||||
|
content: parseTree
|
||||||
})];
|
})];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
|
Loading…
Reference in New Issue
Block a user