2012-01-07 17:33:42 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/list.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var utils = require("../Utils.js");
|
|
|
|
|
2012-01-07 21:54:14 +00:00
|
|
|
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 [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-07 17:33:42 +00:00
|
|
|
exports.macro = {
|
|
|
|
name: "list",
|
|
|
|
types: ["text/html","text/plain"],
|
2012-01-07 18:34:20 +00:00
|
|
|
dependentAll: true, // Tiddlers containing <<list>> macro are dependent on every tiddler
|
2012-01-07 17:33:42 +00:00
|
|
|
params: {
|
|
|
|
type: {byName: "default", type: "text", optional: false},
|
|
|
|
template: {byName: true, type: "tiddler", optional: true},
|
|
|
|
emptyMessage: {byName: true, type: "text", optional: true}
|
|
|
|
},
|
2012-01-15 12:16:28 +00:00
|
|
|
handler: function(type,tiddler,store,params) {
|
2012-01-07 21:54:14 +00:00
|
|
|
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 {
|
2012-01-08 11:03:20 +00:00
|
|
|
var fn = store.compileText(templateType,templateText,type);
|
2012-01-07 21:54:14 +00:00
|
|
|
pushTag("<ul>");
|
|
|
|
for(t=0; t<tiddlers.length; t++) {
|
|
|
|
pushTag("<li>");
|
2012-01-08 11:03:20 +00:00
|
|
|
output.push(fn(store.getTiddler(tiddlers[t]),store,utils));
|
2012-01-07 21:54:14 +00:00
|
|
|
pushTag("</li>");
|
|
|
|
}
|
|
|
|
pushTag("</ul>");
|
|
|
|
return output.join("");
|
|
|
|
}
|
2012-01-07 17:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|