Markup.js icon indicating copy to clipboard operation
Markup.js copied to clipboard

handling {{function|pipe}} like {{function}}

Open moos opened this issue 11 years ago • 2 comments

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);
        }

moos avatar Oct 05 '14 03:10 moos

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. ;)

adammark avatar Oct 07 '14 13:10 adammark

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.

moos avatar Oct 11 '14 19:10 moos