Added verification of macro type compatibility

print-window-tiddler
Jeremy Ruston 2012-01-07 18:33:57 +00:00
rodzic 7a0f94343a
commit 3a98cc5389
1 zmienionych plików z 47 dodań i 51 usunięć

Wyświetl plik

@ -80,7 +80,14 @@ WikiTextParseTree.prototype.compileMacroCall = function(type,name,params) {
var macro = this.store.macros[name], var macro = this.store.macros[name],
p, p,
n; n;
if(macro) { if(!macro) {
this.pushString("{{** Unknown macro '" + name + "' **}}");
return;
}
if(macro.types.indexOf(type) === -1) {
this.pushString("{{** Macro '" + name + "' cannot render to MIME type '" + type + "'**}}");
return;
}
var macroCall = { var macroCall = {
type: "FunctionCall", type: "FunctionCall",
name: { name: {
@ -88,33 +95,25 @@ WikiTextParseTree.prototype.compileMacroCall = function(type,name,params) {
"base": { "base": {
"base": { "base": {
"name": "store", "name": "store",
"type": "Variable" "type": "Variable"},
},
"name": "macros", "name": "macros",
"type": "PropertyAccess" "type": "PropertyAccess"},
},
"name": { "name": {
"type": "StringLiteral", "type": "StringLiteral",
"value": name "value": name},
}, "type": "PropertyAccess"},
"type": "PropertyAccess"
},
"name": "code", "name": "code",
"type": "PropertyAccess" "type": "PropertyAccess"},
},
"arguments": [ { "arguments": [ {
"type": "StringLiteral", "type": "StringLiteral",
"value": type "value": type
}, },{
{
"type": "Variable", "type": "Variable",
"name": "tiddler" "name": "tiddler"
}, },{
{
"type": "Variable", "type": "Variable",
"name": "store" "name": "store"
}, },{
{
type: "ObjectLiteral", type: "ObjectLiteral",
properties: [] properties: []
}] }]
@ -132,9 +131,6 @@ WikiTextParseTree.prototype.compileMacroCall = function(type,name,params) {
}); });
} }
this.output.push(macroCall); this.output.push(macroCall);
} else {
this.pushString("{{** Unknown macro '" + name + "' **}}");
}
}; };
WikiTextParseTree.prototype.compileElementHtml = function(element, options) { WikiTextParseTree.prototype.compileElementHtml = function(element, options) {