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

Use the setvariable widget instead of macrodef

setvariable is more general
This commit is contained in:
Jeremy Ruston 2013-10-13 23:40:11 +01:00
parent 942e463b20
commit cc4940f41f
3 changed files with 6 additions and 56 deletions

View File

@ -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;
})();

View File

@ -41,7 +41,7 @@ SetVariableWidget.prototype.execute = function() {
this.setName = this.getAttribute("name","tiddlerTitle");
this.setValue = this.getAttribute("value");
// Set context variable
this.setVariable(this.setName,this.setValue);
this.setVariable(this.setName,this.setValue,this.parseTreeNode.params);
// Construct the child widgets
this.makeChildWidgets();
};

View File

@ -641,6 +641,11 @@ var tweakParseTreeNodes = function(nodeList) {
var tweakMacroDefinition = function(nodeList) {
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.splice(1,nodeList.length-1);
tweakMacroDefinition(nodeList.children);