Closed ergoithz closed 3 years ago
I'm closing this based on the following reasons:
Mustache.js
lambdas' this
points to the rendering scope, see next comment)parse_and_extract_value(render('{{.}}'))
(strftime example), even tho it won't work on many situations.Thanks for your time.
Some extra context if anyone reaches this issue.
Mustache.js
exposes the rendering scope to lambda functions, and its lambdas look like this:
let scope = {
mylambda(){
return (content, render) => {
return render(content);
};
}
}
Counterintuitively, the lambda is called inside the current rendering scope and not where gets defined, which is extremely useful as it allows referencing that scope via this
.
An example (again, Mustache.js
):
let scope = {
key: 1,
nested: {
key: 2,
},
lambda(){
return (content, render) => {
return render(`${render(content)}${this.key}`);
};
}
};
console.log(Mustache.render('{{#lambda}}value={{/lambda}}', scope));
// value=1
console.log(Mustache.render('{{#nested}}{{#lambda}}value={{/lambda}}{{/nested}}', scope))
// value=2
This essential lambda feature is missing in chevron as, again, there is no way of getting the current rendering scope during a lambda call.
With something like changing the lambda render callable parameter from the current lamda function to a callable object, chevron could cleanly expose the current rendering context (chevron scope) to advanced callable contexts.
In the meantime, we're relying in ugly hacks like:
I'll take some time to make a PR for this.