Ticket #1147 (closed defect: fixed)
<<tiddler>> macro with params not refreshed
| Reported by: | EricShulman | Owned by: | MartinBudden |
|---|---|---|---|
| Priority: | undefined | Milestone: | 2.6 |
| Component: | core | Version: | |
| Severity: | undefined | Keywords: | |
| Cc: |
Description (last modified by EricShulman) (diff)
when <<tiddler SomeTiddler?>> is handled, the resulting span has extra attributes: refresh='content' and tiddler='SomeTiddler?'. If SomeTiddler? is changed, store.notify('SomeTiddler?') triggers refreshDisplay(), which automatically re-renders transcluded content in any span that has these extra attributes.
However, when additional arguments are passed by using <<tiddler SomeTiddler? with: arg arg arg ...>> then the resulting span does NOT get the extra attributes noted above and, as a consequence, the transcluded content is not being refreshed, even though the underlying tiddler has changed.
The following test case illustrates the problem
- create two tiddlers, A and B
- in tiddler A, write:
<<tiddler B>> <<tiddler B with: something>>
- in tiddler B, write:
This is tiddler B (arg=$1)
- note display in tiddler A
- edit tiddler B, press done.
- note revised display in tiddler A is only reflected in the first instance of the macro, but not the second.
To correct this, in config.macros.tiddler.handler, we need to set the 'refresh' and 'tiddler' attributes even when arguments are present in the macro, and also store the tiddler arguments themselves in an attribute (e.g, 'args'), using as a space-separated, bracketed list.
Then, in config.refreshers.content, retrieve and merge the stored arguments (if any) into the tiddler source, and re-render the span with the updated content.
The following changes have been successfully implemented at http://www.TiddlTools.com/#CoreTweaks
config.refreshers.content=function(e,changeList) {
var title = e.getAttribute("tiddler");
var force = e.getAttribute("force");
var args = e.getAttribute("args"); // ADDED
if(force != null || changeList == null || changeList.indexOf(title) != -1) {
removeChildren(e);
// wikify(store.getTiddlerText(title,""),e,null,store.fetchTiddler(title)); // REMOVED
config.macros.tiddler.transclude(e,title,args); // ADDED
return true;
} else
return false;
};
config.macros.tiddler.handler=function(place,macroName,params,wikifier,paramString,tiddler) {
params = paramString.parseParams("name",null,true,false,true);
var names = params[0]["name"];
var tiddlerName = names[0];
var className = names[1] || null;
var args = params[0]["with"];
var wrapper = createTiddlyElement(place,"span",null,className);
// if(!args) { // REMOVED
wrapper.setAttribute("refresh","content");
wrapper.setAttribute("tiddler",tiddlerName);
// } // REMOVED
if(args!==undefined) wrapper.setAttribute("args",'[['+args.join(']] [[')+']]'); // ADDED
this.transclude(wrapper,tiddlerName,args); // REFACTORED TO ...tiddler.transclude
}
// REFACTORED FROM ...tiddler.handler
config.macros.tiddler.transclude=function(wrapper,tiddlerName,args) {
var text = store.getTiddlerText(tiddlerName); if (!text) return;
var stack = config.macros.tiddler.tiddlerStack;
if(stack.indexOf(tiddlerName) !== -1) return;
stack.push(tiddlerName);
try {
if (typeof args == "string") args=args.readBracketedList(); // ADDED
var n = args ? Math.min(args.length,9) : 0;
for(var i=0; i<n; i++) {
var placeholderRE = new RegExp("\\$" + (i + 1),"mg");
text = text.replace(placeholderRE,args[i]);
}
config.macros.tiddler.renderText(wrapper,text,tiddlerName,null); // REMOVED UNUSED 'params'
} finally {
stack.pop();
}
};
