mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-08 08:20:27 +00:00
add getvariablejson and a test tiddler, to see if getvariblejson is of any use
This commit is contained in:
parent
9f0bf45c36
commit
df1413bf1c
31
core/modules/filters/getvariablejson.js
Normal file
31
core/modules/filters/getvariablejson.js
Normal 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
27
editions/tw5.com/tiddlers/test-getvariablejson.tid
Normal file
27
editions/tw5.com/tiddlers/test-getvariablejson.tid
Normal 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>""">>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user