1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-01 01:33:16 +00:00
TiddlyWiki5/core/modules/filterrunprefixes/cascade.js
Jeremy Ruston a350a76a00
Add "cascade" filter run prefix and use it to control view templates (#6168)
* Initial Commit

* Set currentTiddler and ..currentTiddler for filter evaulation

* Precompile the filters for performance

* Add explicit test for empty result when no filter passes

* Use the cascade filter run prefix to choose the view template body template

* Use the cascade mechanism to choose between the edit and view templates

* Simplify cascade filter

Thanks @saqimtiaz

* Add control panel UI for inspecting the template cascades

* Refactor import listing and plugin listing as alternate body templates

As suggested by @pmario

* Refer to $:/core/ui/{View|Edit}Template via their associated config tiddlers

* Fix typo in previous commit

* Add demo of custom story tiddler template

* Tweak control panel wording

* Standardise "Story Tiddler Template" nomenclature

* Add a cascade for the editor template body

* Add a cascade for the view template title

* Avoid unwanted whitespace

* Add a cascade for dynamically choosing tiddler icons
2021-11-15 21:06:47 +00:00

51 lines
1.3 KiB
JavaScript

/*\
title: $:/core/modules/filterrunprefixes/cascade.js
type: application/javascript
module-type: filterrunprefix
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter prefix function
*/
exports.cascade = function(operationSubFunction,options) {
return function(results,source,widget) {
if(results.length !== 0) {
var filterList = operationSubFunction(source,widget),
filterFnList = [];
var inputResults = results.toArray();
results.clear();
$tw.utils.each(inputResults,function(title) {
var result = ""; // If no filter matches, we return an empty string
$tw.utils.each(filterList,function(filter,index) {
if(!filterFnList[index]) {
filterFnList[index] = options.wiki.compileFilter(filter);
}
var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),{
getVariable: function(name) {
switch(name) {
case "currentTiddler":
return "" + title;
case "..currentTiddler":
return widget.getVariable("currentTiddler");
default:
return widget.getVariable(name);
}
}
});
if(output.length !== 0) {
result = output[0];
return false;
}
});
results.push(result);
});
}
}
};
})();