diff --git a/core/modules/filters/getvariable.js b/core/modules/filters/getvariable.js new file mode 100644 index 000000000..43451abed --- /dev/null +++ b/core/modules/filters/getvariable.js @@ -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; +}; + +})(); diff --git a/core/modules/filters/variables.js b/core/modules/filters/variables.js new file mode 100644 index 000000000..fda40a404 --- /dev/null +++ b/core/modules/filters/variables.js @@ -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(); +}; + +})(); diff --git a/editions/tw5.com/tiddlers/filters/examples/getvariable.tid b/editions/tw5.com/tiddlers/filters/examples/getvariable.tid new file mode 100644 index 000000000..4276ac9cf --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/getvariable.tid @@ -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''">> diff --git a/editions/tw5.com/tiddlers/filters/examples/variables.tid b/editions/tw5.com/tiddlers/filters/examples/variables.tid new file mode 100644 index 000000000..f4db9207f --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/variables.tid @@ -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''">> diff --git a/editions/tw5.com/tiddlers/filters/getvariable.tid b/editions/tw5.com/tiddlers/filters/getvariable.tid new file mode 100644 index 000000000..241ec448b --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/getvariable.tid @@ -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, `[]` 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, `[getvariable[]]` gets the value of the variable whose name is given in the variable `myvariable`. + +<<.operator-examples "getvariable">> diff --git a/editions/tw5.com/tiddlers/filters/variables.tid b/editions/tw5.com/tiddlers/filters/variables.tid new file mode 100644 index 000000000..fd8200f24 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/variables.tid @@ -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">>