Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block-helper options.fn() can return promise in some cases. #5

Open
nknapp opened this issue Aug 16, 2015 · 2 comments
Open

Block-helper options.fn() can return promise in some cases. #5

nknapp opened this issue Aug 16, 2015 · 2 comments
Labels

Comments

@nknapp
Copy link
Owner

nknapp commented Aug 16, 2015

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.

@nknapp
Copy link
Owner Author

nknapp commented Aug 17, 2015

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.

@nknapp nknapp added the wontfix label Aug 26, 2016
@nknapp
Copy link
Owner Author

nknapp commented Aug 26, 2016

After thinking about it some more, this is probably unfixable. It will be kept open to be visible to users who have similar problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant