1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Add new "variables" and "getvariables" operators

This commit is contained in:
Jermolene 2019-03-30 10:52:28 +00:00
parent 1c436cbbf3
commit 754c1251a9
6 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,26 @@
/*\
title: $:/core/modules/filters/getvariable.js
type: application/javascript
module-type: filteroperator
Filter operator for replacing input values by the value of the variable with the same name, or blank if the variable is missing
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.getvariable = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
results.push(options.widget.getVariable(title) || "");
});
return results;
};
})();

View File

@ -0,0 +1,26 @@
/*\
title: $:/core/modules/filters/variables.js
type: application/javascript
module-type: filteroperator
Filter operator for returning the names of the active variables
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.variables = function(source,operator,options) {
var names = [];
for(var variable in options.widget.variables) {
names.push(variable);
}
return names.sort();
};
})();

View File

@ -0,0 +1,7 @@
created: 20190330100101453
modified: 20190330100101453
tags: [[getvariable Operator]] [[Operator Examples]]
title: getvariable Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[[currentTiddler]getvariable[]]" "returns the value of the variable ''currentTiddler''">>

View File

@ -0,0 +1,7 @@
created: 20190330100101453
modified: 20190330100101453
tags: [[variables Operator]] [[Operator Examples]]
title: variables Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[variables[]prefix[colour]]" "returns the names of any variables whose names start with ''colour''">>

View File

@ -0,0 +1,17 @@
created: 20190330100101453
modified: 20190330100101453
tags: [[Filter Operators]] [[Special Operators]]
title: getvariable Operator
caption: getvariable
op-purpose: select all values of variables named in the input titles
op-input: a selection of varible names
op-parameter: ignored
op-output: the values of each of the variables named in the input titles (or blank if the variable is not defined)
The usual way to retrieve a variable value within a filter is with the angle brackets notation. For example, `[<currentTiddler>]` will retrieve the value of the variable called `currentTiddler`.
The `getvariable` filter operator provides an alternative way to retrieve a variable. For example, `[[currentTiddler]getvariable[]]` is another way to retrieve the value of the variable `currentTiddler`.
The advantage of `getvariable` is that it makes it possible to work with variables whose name is computed, and not known in advance. For example, `[<myvariable>getvariable[]]` gets the value of the variable whose name is given in the variable `myvariable`.
<<.operator-examples "getvariable">>

View File

@ -0,0 +1,16 @@
created: 20190330100101453
modified: 20190330100101453
tags: [[Filter Operators]] [[Special Operators]] [[Selection Constructors]]
title: variables Operator
type: text/vnd.tiddlywiki
caption: variables
op-purpose: select the names of all the actively defined variables
op-input: ignored
op-parameter: none
op-output: the names of all the actively defined variables
The primary purpose of the `variables` operator is to implement the [[dumpvariables Macro]]:
<$codeblock code={{$:/core/macros/dumpvariables}}/>
<<.operator-examples "variables">>