1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-08 23:20:03 +00:00

Added modulesproperty filter operator and extended modules operator (#6055)

* Added modulesproperty filter operator and extended modules operator. Docs included

* Removed spurious new line
This commit is contained in:
Saq Imtiaz 2021-09-20 09:25:53 +02:00 committed by GitHub
parent 157afda2fc
commit ef2aeac7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 11 deletions

View File

@ -0,0 +1,30 @@
/*\
title: $:/core/modules/filters/moduleproperty.js
type: application/javascript
module-type: filteroperator
Filter [[module-name]moduleproperty[name]] retrieve a module property
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.moduleproperty = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
var value = require(title)[operator.operand || ""];
if(value !== undefined) {
results.push(value);
}
});
results.sort();
return results;
};
})();

View File

@ -17,11 +17,23 @@ Export our filter function
*/ */
exports.modules = function(source,operator,options) { exports.modules = function(source,operator,options) {
var results = []; var results = [];
source(function(tiddler,title) { if(operator.operands.length >= 2) {
$tw.utils.each($tw.modules.types[title],function(moduleInfo,moduleName) { // Return the modules that have the module property specified in the first operand with the value in the second operand
results.push(moduleName); source(function(tiddler,title) {
$tw.utils.each($tw.modules.types[title],function(moduleInfo,moduleName) {
if(require(moduleName)[operator.operands[0]] === operator.operands[1]) {
results.push(moduleName);
}
});
}); });
}); } else {
// Return all the module names without filtering
source(function(tiddler,title) {
$tw.utils.each($tw.modules.types[title],function(moduleInfo,moduleName) {
results.push(moduleName);
});
});
}
results.sort(); results.sort();
return results; return results;
}; };

View File

@ -0,0 +1,11 @@
created: 20210919201407838
modified: 20210919201738739
tags: [[moduleproperty Operator]] [[Operator Examples]]
title: moduleproperty Operator (Examples)
type: text/vnd.tiddlywiki
Get the name of the macro in the module `$:/core/modules/macros/qualify.js`:
<<.operator-example 1 "[[$:/core/modules/macros/qualify.js]moduleproperty[name]]">>
For all macro modules retrieve their name module properties:
<<.operator-example 2 "[[macro]modules[]moduleproperty[name]]">>

View File

@ -1,7 +1,10 @@
created: 20150123221510000 created: 20150123221510000
modified: 20150123221534000 modified: 20210919201037087
tags: [[modules Operator]] [[Operator Examples]] tags: [[modules Operator]] [[Operator Examples]]
title: modules Operator (Examples) title: modules Operator (Examples)
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
<<.operator-example 1 "[[filteroperator]modules[]]">> <<.operator-example 1 "[[filteroperator]modules[]]">>
Get the title of the macro module which a `property` name with value `version`:
<<.operator-example 2 "[[macro]modules[name],[version]]">>

View File

@ -0,0 +1,12 @@
caption: modulesproperty
created: 20210919201126246
modified: 20210919201347702
op-input: a [[selection|Title Selection]] of modules
op-output: the value of the module property as specified in the operand
op-parameter: module property to retrieve
op-purpose: retrieve a module property
tags: [[Filter Operators]] [[Special Operators]]
title: moduleproperty Operator
type: text/vnd.tiddlywiki
<<.operator-examples "moduleproperty">>

View File

@ -1,12 +1,14 @@
caption: modules
created: 20140410103123179 created: 20140410103123179
modified: 20150203185838000 modified: 20210919201148915
op-input: a [[selection|Title Selection]] of module types
op-output: the title of each module with any of the input types
op-parameter: none
op-purpose: select the names of all modules of the input module types
tags: [[Filter Operators]] [[Special Operators]] tags: [[Filter Operators]] [[Special Operators]]
title: modules Operator title: modules Operator
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
caption: modules
op-purpose: select the names of all modules of the input module types <<.from-version "5.2.0">>The <<.op modules>> filter allows two optional operands. When both are specified, it returns the modules with the module property specified in the first operand which has the value in the second operand.
op-input: a [[selection|Title Selection]] of module types
op-parameter: none
op-output: the title of each module with any of the input types
<<.operator-examples "modules">> <<.operator-examples "modules">>