mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-03 20:33:54 +00:00
Use the setvariable widget instead of macrodef
setvariable is more general
This commit is contained in:
parent
942e463b20
commit
cc4940f41f
@ -1,55 +0,0 @@
|
|||||||
/*\
|
|
||||||
title: $:/core/modules/new_widgets/macrodef.js
|
|
||||||
type: application/javascript
|
|
||||||
module-type: new_widget
|
|
||||||
|
|
||||||
Macro definition widget
|
|
||||||
|
|
||||||
\*/
|
|
||||||
(function(){
|
|
||||||
|
|
||||||
/*jslint node: true, browser: true */
|
|
||||||
/*global $tw: false */
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var Widget = require("$:/core/modules/new_widgets/widget.js").widget;
|
|
||||||
|
|
||||||
var MacroDefWidget = function(parseTreeNode,options) {
|
|
||||||
this.initialise(parseTreeNode,options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Inherit from the base widget class
|
|
||||||
*/
|
|
||||||
MacroDefWidget.prototype = new Widget();
|
|
||||||
|
|
||||||
/*
|
|
||||||
Render this widget into the DOM
|
|
||||||
*/
|
|
||||||
MacroDefWidget.prototype.render = function(parent,nextSibling) {
|
|
||||||
this.parentDomNode = parent;
|
|
||||||
this.computeAttributes();
|
|
||||||
this.execute();
|
|
||||||
this.renderChildren(parent,nextSibling);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Compute the internal state of the widget
|
|
||||||
*/
|
|
||||||
MacroDefWidget.prototype.execute = function() {
|
|
||||||
// Set macro definition
|
|
||||||
this.setVariable(this.parseTreeNode.name,this.parseTreeNode.text,this.parseTreeNode.params);
|
|
||||||
// Construct the child widgets
|
|
||||||
this.makeChildWidgets();
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
||||||
*/
|
|
||||||
MacroDefWidget.prototype.refresh = function(changedTiddlers) {
|
|
||||||
return this.refreshChildren(changedTiddlers);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.macrodef = MacroDefWidget;
|
|
||||||
|
|
||||||
})();
|
|
@ -41,7 +41,7 @@ SetVariableWidget.prototype.execute = function() {
|
|||||||
this.setName = this.getAttribute("name","tiddlerTitle");
|
this.setName = this.getAttribute("name","tiddlerTitle");
|
||||||
this.setValue = this.getAttribute("value");
|
this.setValue = this.getAttribute("value");
|
||||||
// Set context variable
|
// Set context variable
|
||||||
this.setVariable(this.setName,this.setValue);
|
this.setVariable(this.setName,this.setValue,this.parseTreeNode.params);
|
||||||
// Construct the child widgets
|
// Construct the child widgets
|
||||||
this.makeChildWidgets();
|
this.makeChildWidgets();
|
||||||
};
|
};
|
||||||
|
@ -641,6 +641,11 @@ var tweakParseTreeNodes = function(nodeList) {
|
|||||||
|
|
||||||
var tweakMacroDefinition = function(nodeList) {
|
var tweakMacroDefinition = function(nodeList) {
|
||||||
if(nodeList && nodeList[0] && nodeList[0].type === "macrodef") {
|
if(nodeList && nodeList[0] && nodeList[0].type === "macrodef") {
|
||||||
|
nodeList[0].type = "setvariable";
|
||||||
|
nodeList[0].attributes = {
|
||||||
|
name: {type: "string", value: nodeList[0].name},
|
||||||
|
value: {type: "string", value: nodeList[0].text}
|
||||||
|
};
|
||||||
nodeList[0].children = nodeList.slice(1);
|
nodeList[0].children = nodeList.slice(1);
|
||||||
nodeList.splice(1,nodeList.length-1);
|
nodeList.splice(1,nodeList.length-1);
|
||||||
tweakMacroDefinition(nodeList.children);
|
tweakMacroDefinition(nodeList.children);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user