mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-28 11:00:27 +00:00
FIx transcluding of functions
This first implementation concatenates the results of the filter (with no separator) and then wikifies the result. The test in this commit is quite interesting...
This commit is contained in:
parent
6207ec4812
commit
9317804464
@ -161,6 +161,7 @@ TranscludeWidget.prototype.collectSlotFillParameters = function() {
|
||||
Get transcluded parse tree nodes as an object {parser:,text:,type:}
|
||||
*/
|
||||
TranscludeWidget.prototype.getTransclusionTarget = function() {
|
||||
var self = this;
|
||||
// Determine whether we're being used in inline or block mode
|
||||
var parseAsInline = !this.parseTreeNode.isBlock;
|
||||
if(this.transcludeMode === "inline") {
|
||||
@ -205,6 +206,25 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
|
||||
}
|
||||
$tw.utils.addAttributeToParseTreeNode(parser.tree[0],name,param["default"])
|
||||
});
|
||||
} else if(srcVariable.isFunctionDefinition) {
|
||||
var actualParams = this.getOrderedTransclusionParameters(),
|
||||
variables = {};
|
||||
$tw.utils.each(srcVariable.params,function(param,index) {
|
||||
var name = param.name;
|
||||
// Parameter names starting with dollar must be escaped to double dollars
|
||||
if(name.charAt(0) === "$") {
|
||||
name = "$" + name;
|
||||
}
|
||||
if(self.hasAttribute(name)) {
|
||||
variables[name] = self.getAttribute(name);
|
||||
} else if(self.hasAttribute(index + "")) {
|
||||
variables[name] = self.getAttribute(index + "");
|
||||
} else {
|
||||
variables[name] = param["default"];
|
||||
}
|
||||
});
|
||||
var result = this.wiki.filterTiddlers(srcVariable.value,this.makeFakeWidgetWithVariables(variables),this.wiki.makeTiddlerIterator([])).join("");
|
||||
parser = this.wiki.parseText(this.transcludeType,result || "",{parseAsInline: parseAsInline, configTrimWhiteSpace: srcVariable.configTrimWhiteSpace});
|
||||
} else {
|
||||
// For macros and ordinary variables, wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__"
|
||||
parser = {
|
||||
|
@ -0,0 +1,30 @@
|
||||
title: Functions/WikifiedFunctions
|
||||
description: Wikified functions
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
\function fn-buffalo(p)
|
||||
[<p>addsuffix[ with a buffalo]]
|
||||
\end
|
||||
|
||||
\procedure proc-buffalo(p)
|
||||
<$text text={{{ [<p>addsuffix[ with a buffalo]] }}}/>
|
||||
\end
|
||||
|
||||
\define macro-buffalo(p)
|
||||
$p$ with a buffalo
|
||||
\end
|
||||
|
||||
<<fn-buffalo "Going to lunch">>
|
||||
|
||||
<<proc-buffalo "Going to lunch">>
|
||||
|
||||
<<macro-buffalo "Going to lunch">>
|
||||
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>Going to lunch with a buffalo</p><p>Going to lunch with a buffalo</p><p>Going to lunch with a buffalo</p>
|
Loading…
Reference in New Issue
Block a user