Markup.js
Markup.js copied to clipboard
handling {{function|pipe}} like {{function}}
Test case:
var context = {
howl: function(){ return 'owooooo!' }
};
var result = Mark.up("Dog doesn't say {{howl}}", context);
// "Dog doesn't say owooooo!"
But...
var result = Mark.up("Dog doesn't say {{howl|upcase}}", context);
// "Dog doesn't say FUNCTION (){ RETURN 'OWOOOOO!' }"
It's too bad pipes break the intuitive function execution. The workaround {{.|call>howl|upcase}} works, but it'd be nice if pipes were supported with the expedited notation.
Haven't thoroughly tested, but seems this snippet should do it:
// Evaluating a function
else if (ctx instanceof Function) {
result = ctx.apply(context);
result = this._eval(result, filters, child);
}
Agree, this would be useful. Let me see what I can do here—if I add another conditional statement, this thing is bound to explode. ;)
If you implement this, probably don't want to execute the function in 'context' context, as I have it above, but rather as result = ctx(), I would think.