1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-27 02:20:28 +00:00
TiddlyWiki5/archive/js/macros/list.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

/*\
title: js/macros/list.js
\*/
(function(){
/*jslint node: true */
"use strict";
var Renderer = require("../Renderer.js").Renderer;
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 [];
}
};
exports.macro = {
name: "list",
dependentAll: true, // Tiddlers containing <<list>> macro are dependent on every tiddler
params: {
type: {byName: "default", type: "text"},
template: {byName: true, type: "tiddler"},
emptyMessage: {byName: true, type: "text"}
},
execute: function() {
2012-01-07 21:54:14 +00:00
var templateType = "text/x-tiddlywiki",
templateText = "<<view title link>>",
template = this.params.template ? this.store.getTiddler(this.params.template) : null,
content = [],
t,
parents = this.parents;
2012-01-07 21:54:14 +00:00
if(template) {
parents = parents.slice(0);
parents.push(template.title);
templateType = template.type;
templateText = template.text;
2012-01-07 21:54:14 +00:00
}
var handler = handlers[this.params.type];
2012-01-07 21:54:14 +00:00
handler = handler || handlers.all;
var tiddlers = handler(this.store);
2012-01-07 21:54:14 +00:00
if(tiddlers.length === 0) {
return [Renderer.TextNode(this.params.emptyMessage || "")];
2012-01-07 21:54:14 +00:00
} else {
var templateTree = this.store.parseText(templateType,templateText).nodes;
2012-01-07 21:54:14 +00:00
for(t=0; t<tiddlers.length; t++) {
var cloneTemplate = [];
for(var c=0; c<templateTree.length; c++) {
cloneTemplate.push(templateTree[c].clone());
}
var listNode = Renderer.ElementNode("li",null,cloneTemplate);
listNode.execute(parents,tiddlers[t]);
content.push(listNode);
2012-01-07 21:54:14 +00:00
}
return [Renderer.ElementNode("ul",null,content)];
2012-01-07 21:54:14 +00:00
}
}
};
})();