1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

Fixed issue where $parameters did nothing with no $transclude (#8203)

* Fixed issue where $parameters did nothing with no $transclude

* Figured I should test \parameters too
This commit is contained in:
Cameron Fischer 2024-06-06 06:20:35 -04:00 committed by GitHub
parent 33bc77f46f
commit 352272905e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -74,6 +74,18 @@ ParametersWidget.prototype.execute = function() {
self.setVariable(variableName,getValue(name));
}
});
} else {
// There is no parent transclude. i.e. direct rendering.
// We use default values only.
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) {
var name = attr.name;
// If the attribute name starts with $$ then reduce to a single dollar
if(name.substr(0,2) === "$$") {
name = name.substr(1);
}
var value = self.getAttribute(attr.name,"");
self.setVariable(name,value);
});
}
// Construct the child widgets
this.makeChildWidgets();

View File

@ -816,6 +816,26 @@ describe("Widget module", function() {
expect(wrapper.innerHTML).toBe("<p>Bval</p>");
});
it("should use default $parameters if directly rendered", function() {
var wiki = new $tw.Wiki();
var text = "<$parameters bee=default $$dollar=bill nothing empty=''>bee=<<bee>>, $dollar=<<$dollar>>, nothing=<<nothing>>, empty=<<empty>></$parameters>";
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
// Render the widget node to the DOM
var wrapper = renderWidgetNode(widgetNode);
// nothing = true in this attribute form because valueless attributes always equal true.
expect(wrapper.innerHTML).toBe("<p>bee=default, $dollar=bill, nothing=true, empty=</p>");
});
it("should use default \\parameters if directly rendered", function() {
var wiki = new $tw.Wiki();
var text = "\\parameters(bee:default $$dollar:bill nothing)\nbee=<<bee>>, $$dollar=<<$$dollar>>, nothing=<<nothing>>";
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
// Render the widget node to the DOM
var wrapper = renderWidgetNode(widgetNode);
// nothing = true in this attribute form because valueless attributes always equal true.
expect(wrapper.innerHTML).toBe("<p>bee=default, $$dollar=bill, nothing=</p>");
});
it("can have more than one macroDef variable imported", function() {
var wiki = new $tw.Wiki();
wiki.addTiddlers([