From f0974740db8c1a7a218fb5becfa0d03135d21487 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 16 Oct 2012 19:06:52 +0100 Subject: [PATCH] Improvements to list macro Allow shorthand list types, and cope with no template being specified --- core/modules/macros/list.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/modules/macros/list.js b/core/modules/macros/list.js index e985d63ce..6a562f593 100644 --- a/core/modules/macros/list.js +++ b/core/modules/macros/list.js @@ -26,6 +26,16 @@ exports.info = { } }; +/* +These types are shorthands for particular filters +*/ +var typeMappings = { + all: "[!is[shadow]]", + missing: "[is[missing]]", + orphans: "[is[orphan]]", + shadowed: "[is[shadow]]" +}; + exports.executeMacro = function() { // Get the list of tiddlers object this.getTiddlerList(); @@ -43,7 +53,16 @@ exports.executeMacro = function() { }; exports.getTiddlerList = function() { - this.list = this.wiki.filterTiddlers(this.params.filter,this.tiddlerTitle); + var filter; + if(this.hasParameter("type")) { + filter = typeMappings[this.params.type]; + } else if(this.hasParameter("filter")) { + filter = this.params.filter; + } + if(!filter) { + filter = "[!is[shadow]]"; + } + this.list = this.wiki.filterTiddlers(filter,this.tiddlerTitle); }; /* @@ -83,6 +102,10 @@ exports.createListElementMacro = function(title) { if(draft && this.hasParameter("editTemplateText")) { template = this.params.editTemplateText; } + // Check for no template specified + if(!template && !templateText) { + templateText = "<>"; + } // Create the tiddler macro return $tw.Tree.Macro("tiddler",{ srcParams: {