Rails HTTP streaming with HAML
Asked Answered
L

2

12

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.

Landlord answered 21/9, 2011 at 18:5 Comment(5)
I suppose it's because HAML has to render the whole page before it can start shipping anything out to the client - that'd be a design issue. I'm not posting this as an answer because I'm not certain and I don't have time to check this just now.Kenwood
@Romain: Thanks for your input. That's my suspicion too, that HAML doesn't translate individual files to ERB, but actually waits for the whole view to be assembled and then serve HTML. Or something like that. This would be a major deal breaker, now that 3.1 is out and streaming is available.Landlord
Have you tried to look if HAML and/or Rails already had a bug report about this? I would imagine it's not impossible to fix HAML (provided we are both correct in our assumption of what's wrong).Kenwood
Goog idea. github.com/nex3/haml/issues/436Landlord
If you're looking for an alternative to ERB for http-streaming, SLIM templates support it out of the box: rubydoc.info/gems/slim/frames#StreamingOdell
L
2

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.

Landlord answered 20/2, 2012 at 19:50 Comment(0)
G
1

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.

Giffy answered 25/9, 2011 at 12:14 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.