1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-09-13 08:16:05 +00:00

Store macros in the render context so that they scope in the expected way

This commit is contained in:
Jeremy Ruston
2012-12-29 23:17:09 +00:00
parent ea13652a64
commit f496cd540e
7 changed files with 69 additions and 16 deletions

View File

@@ -21,11 +21,9 @@ var MacroCallRenderer = function(renderTree,renderContext,parseTreeNode) {
this.renderContext = renderContext;
this.parseTreeNode = parseTreeNode;
// Find the macro definition
var macro,childTree;
if($tw.utils.hop(this.renderTree.parser.macroDefinitions,this.parseTreeNode.name)) {
macro = this.renderTree.parser.macroDefinitions[this.parseTreeNode.name];
}
var macro = this.findMacroDefinition(this.parseTreeNode.name);
// Insert an error message if we couldn't find the macro
var childTree;
if(!macro) {
childTree = [{type: "text", text: "<<Undefined macro: " + this.parseTreeNode.name + ">>"}];
} else {
@@ -38,6 +36,20 @@ var MacroCallRenderer = function(renderTree,renderContext,parseTreeNode) {
this.children = this.renderTree.createRenderers(this.renderContext,childTree);
};
/*
Find a named macro definition
*/
MacroCallRenderer.prototype.findMacroDefinition = function(name) {
var context = this.renderContext;
while(context) {
if(context.macroDefinitions && context.macroDefinitions[name]) {
return context.macroDefinitions[name];
}
context = context.parentContext;
}
return undefined;
};
/*
Expand the parameters in a block of text
*/

View File

@@ -0,0 +1,30 @@
/*\
title: $:/core/modules/rendertree/renderers/macrodef.js
type: application/javascript
module-type: wikirenderer
Macro definition renderer
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Macro definition renderer
*/
var MacroDefRenderer = function(renderTree,renderContext,parseTreeNode) {
// Store state information
this.renderTree = renderTree;
this.renderContext = renderContext;
this.parseTreeNode = parseTreeNode;
// Save the macro definition into the render context
this.renderContext.macroDefinitions = this.renderContext.macroDefinitions || {};
this.renderContext.macroDefinitions[this.parseTreeNode.name] = this.parseTreeNode;
};
exports.macrodef = MacroDefRenderer
})();

View File

@@ -106,7 +106,14 @@ WidgetRenderer.prototype.refreshInDom = function(changedTiddlers) {
};
WidgetRenderer.prototype.getContextTiddlerTitle = function() {
return this.renderContext ? this.renderContext.tiddlerTitle : undefined;
var context = this.renderContext;
while(context) {
if($tw.utils.hop(context,"tiddlerTitle")) {
return context.tiddlerTitle;
}
context = context.parentContext;
}
return undefined;
};
/*