Block-helper `options.fn()` can return promise in some cases.
In the following example, options.fn() returns a promise instead of a string.
var promisedHandlebars = require('../')
var Q = require('q')
var Handlebars = promisedHandlebars(require('handlebars'))
// Register a helper that returns a promise for a boolean
Handlebars.registerHelper('eventually-true', function () {
return Q.delay(100).then(function () {
return true
})
})
// Trim whitespaces from block-content result.
Handlebars.registerHelper('trim', function(options) {
return options.fn().trim();
});
var template = Handlebars.compile('{{#trim}}{{#if (eventually-true)}} abc{{/if}}{{/trim}}')
// The whole compiled function returns a promise as well
template({}).done(console.log)
The if-helper returns a promise because it has a promise as argument. This promise has a toString()-method that creates a placeholder, but it does not have a .trim() method.
The solution would be to check if the helper is used as a block helper and then convert the return value to a string in the helper wrapper.
This implies the assumption that block-helpers can never be used in other helpers arguments (which is probably true).
However, simple helpers must be able to return promises, which can be seen in the same example.
After thinking about it some more, this is probably unfixable. It will be kept open to be visible to users who have similar problems.