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

Partials don't work with Jade #30

Open
jimpo opened this issue Nov 25, 2012 · 4 comments
Open

Partials don't work with Jade #30

jimpo opened this issue Nov 25, 2012 · 4 comments

Comments

@jimpo
Copy link
Contributor

jimpo commented Nov 25, 2012

jade.render has the signature of an asynchronous function, using a callback instead of returning the rendered HTML. Line 297 of index.js assumes that jade.render will return HTML. My hack to get this to work is (in Coffeescript):

partials.register '.jade', (str, options) ->
  tmpl = null
  jade.render(str, options, (err, value) ->
    throw err if err?
    tmpl = value
  )
  return tmpl

This only works because jade.render actually renders the template synchronously so there's no race condition, but this is super ugly and could break in future versions of Jade if jade.render actual becomes asychronous.

@slaskis
Copy link
Member

slaskis commented Nov 26, 2012

Do you think this issue is related to #28?

@jimpo
Copy link
Contributor Author

jimpo commented Nov 26, 2012

Maybe. I remember I was getting that error and when I looked into the code I found this bug, but I don't remember if the above fixed the issue in #28 or whether I did something else.

@jimpo
Copy link
Contributor Author

jimpo commented Nov 26, 2012

See pugjs/pug#394. TJ Holowaychuk describes the rationale behind Jade's async render. This is, I believe, sort of a fundamental problem because partials have to be computed synchronously.

@jimpo
Copy link
Contributor Author

jimpo commented Nov 26, 2012

Or it seems you can set the jade partial renderer to use jade.compile instead of jade.render.

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

No branches or pull requests

2 participants