mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 17:10:29 +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"},
|
||||
history: {byName: true, type: "tiddler"},
|
||||
template: {byName: true, type: "tiddler"},
|
||||
templateText: {byName: true, type: "text"},
|
||||
editTemplate: {byName: true, type: "tiddler"},
|
||||
editTemplateText: {byName: true, type: "text"},
|
||||
emptyMessage: {byName: true, type: "text"},
|
||||
listviewTiddler: {byName: true, type: "tiddler"},
|
||||
listview: {byName: true, type: "text"},
|
||||
@ -145,28 +143,32 @@ Create the tiddler macro needed to represent a given tiddler
|
||||
exports.createListElementMacro = function(title) {
|
||||
// Check if the tiddler is a draft
|
||||
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
|
||||
var template = this.params.template,
|
||||
templateText = this.params.templateText;
|
||||
if(draft && this.hasParameter("editTemplate")) {
|
||||
templateTree = undefined;
|
||||
if(isDraft && this.hasParameter("editTemplate")) {
|
||||
template = this.params.editTemplate;
|
||||
}
|
||||
if(draft && this.hasParameter("editTemplateText")) {
|
||||
template = this.params.editTemplateText;
|
||||
}
|
||||
// Check for no template specified
|
||||
if(!template && !templateText) {
|
||||
templateText = "<<view title link>>";
|
||||
// Check for not having a template
|
||||
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;
|
||||
}
|
||||
}
|
||||
// Create the tiddler macro
|
||||
return $tw.Tree.Macro("tiddler",{
|
||||
srcParams: {
|
||||
target: title,
|
||||
template: template,
|
||||
templateText: templateText
|
||||
template: template
|
||||
},
|
||||
wiki: this.wiki
|
||||
wiki: this.wiki,
|
||||
content: templateTree
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -58,7 +58,6 @@ exports.info = {
|
||||
target: {byName: "default", type: "tiddler"},
|
||||
targetVia: {byName: true, type: "tiddler"},
|
||||
template: {byName: true, type: "tiddler"},
|
||||
templateText: {byName: true, type: "text"},
|
||||
"with": {byName: true, type: "text", dependentAll: true}
|
||||
}
|
||||
};
|
||||
@ -98,8 +97,8 @@ exports.executeMacro = function() {
|
||||
renderTitle = this.tiddlerTitle;
|
||||
}
|
||||
// Get the render tree for the template
|
||||
if(this.hasParameter("templateText")) {
|
||||
renderTemplateTree = this.wiki.parseText("text/vnd.tiddlywiki",this.params.templateText).tree;
|
||||
if(this.content.length > 0) {
|
||||
renderTemplateTree = this.content;
|
||||
} else {
|
||||
if(this.hasParameter("template")) {
|
||||
renderTemplateTitle = this.params.template;
|
||||
|
@ -34,7 +34,7 @@ exports.parse = function(match,isBlock) {
|
||||
match = regExp.exec(this.source);
|
||||
if(match && match.index === this.pos) {
|
||||
this.pos = match.index + match[0].length;
|
||||
var macro, params = {};
|
||||
var macro, params = {}, parseTree;
|
||||
// Check if it is a single tiddler
|
||||
if(match[1]) {
|
||||
macro = "tiddler";
|
||||
@ -48,11 +48,12 @@ exports.parse = function(match,isBlock) {
|
||||
params.template = match[3];
|
||||
}
|
||||
if(match[4]) {
|
||||
params.templateText = match[4];
|
||||
parseTree = this.wiki.parseText("text/vnd.tiddlywiki",match[4]).tree;
|
||||
}
|
||||
return [$tw.Tree.Macro(macro,{
|
||||
srcParams: params,
|
||||
wiki: this.wiki
|
||||
wiki: this.wiki,
|
||||
content: parseTree
|
||||
})];
|
||||
}
|
||||
return [];
|
||||
|
Loading…
Reference in New Issue
Block a user