1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-12 10:20:26 +00:00

Add support for $:/tags/Global

This commit is contained in:
jeremy@jermolene.com 2022-05-26 21:11:53 +01:00
parent dec45f0fc3
commit 6f9f92fa69
3 changed files with 49 additions and 18 deletions

View File

@ -1075,22 +1075,38 @@ exports.makeWidget = function(parser,options) {
options = options || {};
var widgetNode = {
type: "widget",
children: []
},
currWidgetNode = widgetNode;
// Create set variable widgets for each variable
$tw.utils.each(options.variables,function(value,name) {
var setVariableWidget = {
type: "set",
children: [{
type: "importvariables",
attributes: {
filter: {
name: "filter",
type: "string",
value: "[all[shadows+tiddlers]tag[$:/tags/Global]!is[draft]]"
}
},
isBlock: false,
children: []
}]
},
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

View File

@ -0,0 +1,19 @@
title: Globals/Simple
description: Global procedures
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<<this-is-one>>
+
title: One
tags: $:/tags/Global
\procedure this-is-one() ONE
+
title: ExpectedResult
<p>ONE</p>

View File

@ -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) {