From 6f9f92fa699067b0912e6f36a93888bf80f3f5d9 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Thu, 26 May 2022 21:11:53 +0100 Subject: [PATCH] Add support for $:/tags/Global --- core/modules/wiki.js | 38 +++++++++++++------ .../tiddlers/tests/data/globals/Simple.tid | 19 ++++++++++ .../jasmine/run-wiki-based-tests.js | 10 ++--- 3 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 editions/test/tiddlers/tests/data/globals/Simple.tid diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 49c81930e..9fd254be9 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1075,22 +1075,38 @@ exports.makeWidget = function(parser,options) { options = options || {}; var widgetNode = { type: "widget", - children: [] + children: [{ + type: "importvariables", + attributes: { + filter: { + name: "filter", + type: "string", + value: "[all[shadows+tiddlers]tag[$:/tags/Global]!is[draft]]" + } + }, + isBlock: false, + children: [] + }] }, - currWidgetNode = widgetNode; - // Create set variable widgets for each variable - $tw.utils.each(options.variables,function(value,name) { - var setVariableWidget = { - type: "set", + currWidgetNode = widgetNode.children[0]; + // Create let variable widget for variables + if($tw.utils.count(options.variables) > 0) { + var letVariableWidget = { + type: "let", attributes: { - name: {type: "string", value: name}, - value: {type: "string", value: value} }, children: [] }; - currWidgetNode.children = [setVariableWidget]; - currWidgetNode = setVariableWidget; - }); + $tw.utils.each(options.variables,function(value,name) { + letVariableWidget.attributes[name] = { + name: name, + type: "string", + value: "" + value + } + }); + currWidgetNode.children = [letVariableWidget]; + currWidgetNode = letVariableWidget; + } // Add in the supplied parse tree nodes currWidgetNode.children = parser ? parser.tree : []; // Create the widget diff --git a/editions/test/tiddlers/tests/data/globals/Simple.tid b/editions/test/tiddlers/tests/data/globals/Simple.tid new file mode 100644 index 000000000..6e4d0fc06 --- /dev/null +++ b/editions/test/tiddlers/tests/data/globals/Simple.tid @@ -0,0 +1,19 @@ +title: Globals/Simple +description: Global procedures +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim + +<> ++ +title: One +tags: $:/tags/Global + +\procedure this-is-one() ONE ++ +title: ExpectedResult + +

ONE

\ No newline at end of file diff --git a/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js b/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js index 4db3e232f..6f12aaf89 100644 --- a/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js +++ b/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js @@ -65,16 +65,12 @@ describe("Wiki-based tests", function() { return tiddlers; } - function createWidgetNode(parseTreeNode,wiki) { - return new widget.widget(parseTreeNode,{ - wiki: wiki, - document: $tw.fakeDocument - }); + function createWidgetNode(parser,wiki) { + return wiki.makeWidget(parser); } function parseText(text,wiki,options) { - var parser = wiki.parseText("text/vnd.tiddlywiki",text,options); - return parser ? {type: "widget", children: parser.tree} : undefined; + return wiki.parseText("text/vnd.tiddlywiki",text,options); } function renderWidgetNode(widgetNode) {