publicclass / express-partials

Express 3.x Layout & Partial support.
182 stars 146 forks source link

Partials don't work with Jade #30

Open jimpo opened 11 years ago

jimpo commented 11 years ago

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 commented 11 years ago

Do you think this issue is related to #28?

jimpo commented 11 years ago

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 commented 11 years ago

See https://github.com/visionmedia/jade/issues/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 commented 11 years ago

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