2012-01-07 17:33:42 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/list.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-16 20:38:10 +00:00
|
|
|
var Renderer = require("../Renderer.js").Renderer;
|
2012-01-07 17:33:42 +00:00
|
|
|
|
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: {
|
2012-02-17 17:32:32 +00:00
|
|
|
type: {byName: "default", type: "text"},
|
|
|
|
template: {byName: true, type: "tiddler"},
|
|
|
|
emptyMessage: {byName: true, type: "text"}
|
2012-01-07 17:33:42 +00:00
|
|
|
},
|
2012-02-16 20:38:10 +00:00
|
|
|
execute: function(macroNode,tiddler,store) {
|
2012-01-07 21:54:14 +00:00
|
|
|
var templateType = "text/x-tiddlywiki",
|
|
|
|
templateText = "<<view title link>>",
|
2012-02-16 20:38:10 +00:00
|
|
|
template = macroNode.params.template ? store.getTiddler(macroNode.params.template) : null,
|
|
|
|
content = [],
|
2012-01-07 21:54:14 +00:00
|
|
|
t;
|
|
|
|
if(template) {
|
2012-01-17 13:01:55 +00:00
|
|
|
templateType = template.type;
|
|
|
|
templateText = template.text;
|
2012-01-07 21:54:14 +00:00
|
|
|
}
|
2012-02-16 20:38:10 +00:00
|
|
|
var handler = handlers[macroNode.params.type];
|
2012-01-07 21:54:14 +00:00
|
|
|
handler = handler || handlers.all;
|
|
|
|
var tiddlers = handler(store);
|
|
|
|
if(tiddlers.length === 0) {
|
2012-02-16 20:38:10 +00:00
|
|
|
return [Renderer.TextNode(macroNode.params.emptyMessage || "")];
|
2012-01-07 21:54:14 +00:00
|
|
|
} else {
|
2012-02-16 20:38:10 +00:00
|
|
|
var templateTree = store.parseText(templateType,templateText).tree;
|
2012-01-07 21:54:14 +00:00
|
|
|
for(t=0; t<tiddlers.length; t++) {
|
2012-02-16 20:38:10 +00:00
|
|
|
var cloneTemplate = [];
|
|
|
|
for(var c=0; c<templateTree.length; c++) {
|
|
|
|
cloneTemplate.push(templateTree[c].clone());
|
|
|
|
}
|
|
|
|
var listNode = Renderer.ElementNode("li",null,cloneTemplate);
|
|
|
|
listNode.execute(store.getTiddler(tiddlers[t]));
|
|
|
|
content.push(listNode);
|
2012-01-07 21:54:14 +00:00
|
|
|
}
|
2012-02-16 20:38:10 +00:00
|
|
|
return [Renderer.ElementNode("ul",null,content)];
|
2012-01-07 21:54:14 +00:00
|
|
|
}
|
2012-01-07 17:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|