mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Extend macrocall widget to take parameters both from the parse tree node and the attributes
This allows us to invoke macros using the ordinary widget syntax, which in turn allows us to use features like indirection on the parameters.
This commit is contained in:
parent
6b9b75142b
commit
55d479c540
@ -37,8 +37,13 @@ MacroCallWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
Compute the internal state of the widget
|
Compute the internal state of the widget
|
||||||
*/
|
*/
|
||||||
MacroCallWidget.prototype.execute = function() {
|
MacroCallWidget.prototype.execute = function() {
|
||||||
|
// Merge together the parameters specified in the parse tree with the specified attributes
|
||||||
|
var params = this.parseTreeNode.params ? this.parseTreeNode.params.slice(0) : [];
|
||||||
|
$tw.utils.each(this.attributes,function(attribute,name) {
|
||||||
|
params.push({name: name, value: attribute});
|
||||||
|
});
|
||||||
// Get the macro value
|
// Get the macro value
|
||||||
var text = this.getVariable(this.parseTreeNode.name,this.parseTreeNode.params);
|
var text = this.getVariable(this.parseTreeNode.name || this.getAttribute("$name"),params);
|
||||||
// Parse the macro
|
// Parse the macro
|
||||||
var parser = this.wiki.new_parseText("text/vnd.tiddlywiki",text,
|
var parser = this.wiki.new_parseText("text/vnd.tiddlywiki",text,
|
||||||
{parseAsInline: !this.parseTreeNode.isBlock}),
|
{parseAsInline: !this.parseTreeNode.isBlock}),
|
||||||
@ -51,7 +56,14 @@ MacroCallWidget.prototype.execute = function() {
|
|||||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||||
*/
|
*/
|
||||||
MacroCallWidget.prototype.refresh = function(changedTiddlers) {
|
MacroCallWidget.prototype.refresh = function(changedTiddlers) {
|
||||||
return this.refreshChildren(changedTiddlers);
|
var changedAttributes = this.computeAttributes();
|
||||||
|
if($tw.utils.count(changedAttributes) > 0) {
|
||||||
|
// Rerender ourselves
|
||||||
|
this.refreshSelf();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return this.refreshChildren(changedTiddlers);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.macrocall = MacroCallWidget;
|
exports.macrocall = MacroCallWidget;
|
||||||
|
Loading…
Reference in New Issue
Block a user