kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Implemented <<list>> macro
rodzic
b959c6ea22
commit
cd0ecf6e1c
|
@ -9,6 +9,29 @@ title: js/macros/list.js
|
||||||
|
|
||||||
var utils = require("../Utils.js");
|
var utils = require("../Utils.js");
|
||||||
|
|
||||||
|
var handlers = {
|
||||||
|
all: function(store) {
|
||||||
|
return store.getTitles("title","excludeLists");
|
||||||
|
},
|
||||||
|
missing: function(store) {
|
||||||
|
return store.getMissingTitles();
|
||||||
|
},
|
||||||
|
orphans: function(store) {
|
||||||
|
return store.getOrphanTitles();
|
||||||
|
},
|
||||||
|
shadowed: function(store) {
|
||||||
|
return store.getShadowTitles();
|
||||||
|
},
|
||||||
|
touched: function(store) {
|
||||||
|
// Server syncing isn't implemented yet
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
filter: function(store) {
|
||||||
|
// Filters aren't implemented yet
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.macro = {
|
exports.macro = {
|
||||||
name: "list",
|
name: "list",
|
||||||
types: ["text/html","text/plain"],
|
types: ["text/html","text/plain"],
|
||||||
|
@ -19,7 +42,34 @@ exports.macro = {
|
||||||
emptyMessage: {byName: true, type: "text", optional: true}
|
emptyMessage: {byName: true, type: "text", optional: true}
|
||||||
},
|
},
|
||||||
code: function(type,tiddler,store,params) {
|
code: function(type,tiddler,store,params) {
|
||||||
return "Listing!";
|
var templateType = "text/x-tiddlywiki",
|
||||||
|
templateText = "<<view title link>>",
|
||||||
|
template = params.template ? store.getTiddler(params.template) : null,
|
||||||
|
output = [],
|
||||||
|
isHtml = type === "text/html",
|
||||||
|
encoder = isHtml ? utils.htmlEncode : function(x) {return x;},
|
||||||
|
pushTag = isHtml ? function(x) {output.push(x);} : function(x) {},
|
||||||
|
handler,
|
||||||
|
t;
|
||||||
|
if(template) {
|
||||||
|
templateType = template.fields.type;
|
||||||
|
templateText = template.fields.text;
|
||||||
|
}
|
||||||
|
handler = handlers[params.type];
|
||||||
|
handler = handler || handlers.all;
|
||||||
|
var tiddlers = handler(store);
|
||||||
|
if(tiddlers.length === 0) {
|
||||||
|
return params.emptyMessage ? encoder(params.emptyMessage) : "";
|
||||||
|
} else {
|
||||||
|
pushTag("<ul>");
|
||||||
|
for(t=0; t<tiddlers.length; t++) {
|
||||||
|
pushTag("<li>");
|
||||||
|
output.push(store.renderText(templateType,templateText,type,tiddlers[t]));
|
||||||
|
pushTag("</li>");
|
||||||
|
}
|
||||||
|
pushTag("</ul>");
|
||||||
|
return output.join("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue