Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails HTTP streaming with HAML

There appears to be an issue with using HTTP streaming with HAML projects in rails. It works perfectly if I use ERB instead. Apparently, I'm not the only one with this problem.

It doesn't work with placing stream at the top of the controller, or with using render :stream => true in the action.

How can I get HAML and HTTP streaming to play nicely together?

Update: I've opened an issue on the gem's page, here.

like image 623
Julio Santos Avatar asked Sep 21 '11 18:09

Julio Santos


2 Answers

This is not yet supported by HAML (source):

HTTP streaming is the sort of thing that would require a substantial set of modifications to the core Haml engine. It's only moderately tricky to get it working even in basic cases, but when you factor in things like the whitespace-eating operators it gets much more difficult.

This isn't something I'm opposed to in theory, but it's also not something that's high on my priority list given the difficulty of implementing it.

like image 142
Julio Santos Avatar answered Nov 11 '22 09:11

Julio Santos


The internals of Haml are such that it is indeed writing out to a buffer as it goes along. However, the "standard" API that Rails has traditionally provided for templating languages is a fairly straightforward in-and-out call. I don't think Haml does currently have "streaming support", but its simply more of an API issue than anything else.

I'm curious as to how Rails is plugging into ERB to do this.

like image 21
hcatlin Avatar answered Nov 11 '22 10:11

hcatlin