Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Jade support for jade.compile() in addition to jade.render() #72

Open
kangas opened this issue Mar 2, 2016 · 5 comments
Open

Jade support for jade.compile() in addition to jade.render() #72

kangas opened this issue Mar 2, 2016 · 5 comments

Comments

@kangas
Copy link

kangas commented Mar 2, 2016

The current Jade compiler always calls jade.render to produce text/html.

I want to enhance the compiler so it is also able to return application/javascript (via jade.compile) when a javascript file calls require('file.jade').

Any suggestions on how to approach this?

Questions:

  • Is it possible for one compiler with one input mime type produce two output mime types? And write two distinct cache entries?
  • If so, how may a compiler detect whether require-hook or protocol-hook was invoked for a given file?
@anaisbetts
Copy link
Contributor

Is it possible for one compiler with one input mime type produce two output mime types? And write two distinct cache entries?

Not at the moment, though it's not impossible.

If so, how may a compiler detect whether require-hook or protocol-hook was invoked for a given file?

It can't unfortunately, we'd have to add that. Right now you can get away with returning JS for compileSync and HTML for compile, but that's mostly happenstance.

As an aside, what does jade.compile actually return? JS code that will render a Jade template?

@durran
Copy link

durran commented Mar 2, 2016

jade.compile returns JS function that renders the template.

@anaisbetts
Copy link
Contributor

Hm, I'm not sure that will work, because node.js's module framework expects that require.extensions returns some kind of string - if you return an already instantiated Function it'll blow up

@kangas
Copy link
Author

kangas commented Mar 3, 2016

Paul, thanks for the feedback. Durran is correct, jade.compile returns a JS function which, when invoked, renders within a context. It's described here: http://jade-lang.com/api/

We are presently working around this by invoking jade.compile directly as needed, but this implies that we'll also ship Jade plus its dependencies in our release build. I'd like to solve this in due time.

@anaisbetts
Copy link
Contributor

@kangas I think we can make this work but it'll be ugly, we can take the Function returned by Jade and call toString on it, turning it back into JS source 😢

@stale stale bot added the wontfix label Mar 15, 2017
@zeke zeke removed the wontfix label Mar 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants