add getvariablejson and a test tiddler, to see if getvariblejson is of any use

This commit is contained in:
pmario 2024-05-06 12:10:05 +02:00
parent 9f0bf45c36
commit df1413bf1c
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,31 @@
/*\
title: $:/core/modules/filters/getvariablejson.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.getvariablejson = function(source,operator,options) {
var results = [],
space = operator.operands[1] || null,
replacerList = (operator.operands[2]) ? operator.operands[2].split(" ") : null,
widget = options.widget;
source(function(tiddler,title) {
var variable = widget.getVariableInfo(title, {}),
text = JSON.stringify(variable,replacerList,space);
results.push(text || "");
});
return results;
};
})();

View File

@ -0,0 +1,27 @@
created: 20240506064659892
modified: 20240506100851338
tags:
title: test-getvariablejson
type: text/vnd.tiddlywiki
\define test-macro(a:10) test macro
\procedure test-proc(a:10) test proc
\function my.test(x:3, abc:def) [<test-proc>split[ ]]
\define elements() srcVariable params name default
\define openBracket() [
\define closeBracket() ]
<<.example 1 """\procedure test-proc(a:10) test proc
\function my.test(x:3, abc:def) [<test-proc>split[ ]]
\function tab() [charcode[9]]
<pre><$text text={{{[[my.test]getvariablejson[],<tab>]}}}/></pre>
""">>
<<.example 2 """<pre><$text text={{{[[my.test]getvariablejson[],<tab>] +[jsonextract[srcVariable],[params]] +[format:json<tab>] }}}/></pre>""">>