Open peterjwest opened 9 years ago
You can already pass streams as locals, you just can't then pipe them to the output.
That's kinda what I meant, not much use having a stream in a jade template if you can't pump out the data.
If you added a method to your stream that returns a promise you could then write something like:
- stream.on('data', buf.push);
- yield stream.wait();
in your template.
Would that wait until the whole stream has processed before outputting? I was hoping to stream data to the HTTP response as data comes into the input stream.
The stream given by then-jade
can be sent to the HTTP response. This is how I use it.
From what I understand, you are asking if you can interleave the jade stream with external streams coming via locals
like
body
div = << stream1 >>
body
div = << stream2 >>
with
locals = { stream1: any Readable stream, stream2: any Readable stream }
I think that the solution given by @ForbesLindesay would work even though it would not handle backpressure on stream1 & stream2 (the on('data') will put them in flowing mode). As an answer to your question, yes, it would flush all the stream in the correct place.
This is untested code but you could probably implement his solution with barrage
and a mixin.
var barrage = require('barrage');
locals = {
barrage: barrage,
stream1: any Readable stream,
stream2: any Readable stream
}
and then in your jade file
mixin streamit(stream)
- var s = barrage(stream)
- s.on('data', buf.push)
- yield (s.wait())
body
div
+streamit(stream1)
div
+streamit(stream2)
Keep us posted !
Any chance there could be support for streams as locals?