mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-04 17:16:18 +00:00
Initial Commit
This commit is contained in:
parent
b6ce353a7d
commit
fc3a764199
36
core/modules/filterrunprefixes/cascade.js
Normal file
36
core/modules/filterrunprefixes/cascade.js
Normal file
@ -0,0 +1,36 @@
|
||||
/*\
|
||||
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);
|
||||
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) {
|
||||
var output = options.wiki.filterTiddlers(filter,widget,options.wiki.makeTiddlerIterator([title]));
|
||||
if(output.length !== 0) {
|
||||
result = output[0];
|
||||
return false;
|
||||
}
|
||||
});
|
||||
results.push(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
@ -288,6 +288,31 @@ describe("'reduce' and 'intersection' filter prefix tests", function() {
|
||||
tags: ["cakes","with tea"],
|
||||
text: "Does anyone eat pound cake?"
|
||||
});
|
||||
wiki.addTiddler({
|
||||
title: "$:/filter1",
|
||||
text: "[tag[cakes]then[It is customary]]",
|
||||
tags: "$:/tags/Filter"
|
||||
});
|
||||
wiki.addTiddler({
|
||||
title: "$:/filter2",
|
||||
text: "[tag[shopping]then[It is not customary]]",
|
||||
tags: "$:/tags/Filter"
|
||||
});
|
||||
wiki.addTiddler({
|
||||
title: "$:/filter3",
|
||||
text: "[[Just a default]]",
|
||||
tags: "$:/tags/Filter"
|
||||
});
|
||||
wiki.addTiddler({
|
||||
title: "$:/tags/Filter",
|
||||
list: "$:/filter1 $:/filter2 $:/filter3"
|
||||
});
|
||||
|
||||
it("should handle the :cascade filter prefix", function() {
|
||||
expect(wiki.filterTiddlers("[[Rice Pudding]] :cascade[all[shadows+tiddlers]tag[$:/tags/Filter]get[text]]").join(",")).toBe("It is not customary");
|
||||
expect(wiki.filterTiddlers("[[chocolate cake]] :cascade[all[shadows+tiddlers]tag[$:/tags/Filter]get[text]]").join(",")).toBe("It is customary");
|
||||
expect(wiki.filterTiddlers("[[Sparkling water]] :cascade[all[shadows+tiddlers]tag[$:/tags/Filter]get[text]]").join(",")).toBe("Just a default");
|
||||
});
|
||||
|
||||
it("should handle the :reduce filter prefix", function() {
|
||||
expect(wiki.filterTiddlers("[tag[shopping]] :reduce[get[quantity]add<accumulator>]").join(",")).toBe("22");
|
||||
|
Loading…
Reference in New Issue
Block a user