Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Inner whitespace nuke is inconsistent with loops #465

Open
nex3 opened this Issue · 15 comments

6 participants

@nex3
Owner
%ul<
  = "foo"
  = "bar"
  = "baz"

produces

<ul>foobarbaz</ul>

but

%ul<
  - for str in %w[foo bar baz]
    = str

produces

<ul>foo
bar
baz</ul>
@richardkmichael richardkmichael referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@richardkmichael richardkmichael referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@richardkmichael richardkmichael referenced this issue from a commit in richardkmichael/haml
@richardkmichael richardkmichael [Haml] Make inner whitespace nuke consistent with loops. #465
%ul<
  - for str in %w[foo bar baz]
    = str

<ul>foobarbaz</ul>
3062319
@dennybritz

Good job. It would be great if we could include this ASAP since it keeps bothering me over and over again...

@jasonkuhrt

@dennybritz +1

I first reported this bug in #463 and we're still suffering from it to this day.

@jasonkuhrt

@richardkmichael I noticed something that still does not work:

.fluid-queue<
  = render :partial => "searches/result", :collection => @results

In order to remove whitespace from the above we have to do this:

.fluid-queue<
  - @results.each do |job|
    = render :partial => "searches/api/job_result", :object => job

@richardkmichael Can you confirm the same thing?

@richardkmichael

@jasonkuhrt It's that exact case I was originally looking at with @chooh! Yes, it still doesn't work, but it's on my short list to review.

In fact, I suspect what I've done is rather hackish. In particular, it's worrying I didn't so anything symmetric with "outer whitespace". In this PR, all I was looking for was some comment about the general approach.

@jasonkuhrt

@richardkmichael Oh and in all cases I noticed that I need to set :ugly to true. Not a big deal but again not sure if this is expected or not. Thanks for your contributions to this issue!

@jasonkuhrt

@richardkmichael Any luck with checking out the case with :collections ?

@richardkmichael
@jasonkuhrt

@richardkmichael No worries, was just curious. Great to hear it's still on your radar.

@norman norman referenced this issue from a commit
@richardkmichael richardkmichael Make inner whitespace nuke consistent with loops.
%ul<
  - for str in %w[foo bar baz]
    = str

<ul>foobarbaz</ul>

See #465 for discussion.
Closes #489.

Signed-off-by: Norman Clarke <norman@njclarke.com>
1a30396
@norman
Owner

@richardkmichael thanks a lot for working on this. If you can look into the issue with collections that would be great. I already pulled #489 since even without that it's already a nice step forward.

@richardkmichael

Definitely will do; just need to block some time for it.

@jasonkuhrt

Hey @richardkmichael, have you had a chance to look yet? I'm just curious if it's a matter of time or the problem is really thorny? Cheers

@richardkmichael
@richardkmichael

@jasonkuhrt TL;DR -- I looked at it this afternoon and it's messier than I thought. I won't get to it any time soon.

AFAICT, it's not as simple as adding a nuke_inner_whitespace or nuke_outer_whitespace call.

If you want

%div
  - @objects.each do |object|
    = render :partial => 'object', :object => object

to behave like

%div
  = render :partial => 'object', :collection => @objects

Where the partial contains:

%div>
  = object

Then it means outputting:

    <div>
      <div>
        Block 1
      </div><div>
        Block 2
      </div><div>
        Block 3
      </div><div>
        Block 4
      </div><div>
        Block 5
      </div>
    </div>

Notice, it's not unequivocally nuking whitespace outside the inner div elements. Specifically, the first div appears on a newline, and the last div preserves its trailing newline.

This work is done inside the compiler, (push_script in this case) using the various *_merged_text methods.

https://github.com/haml/haml/blob/master/lib/haml/compiler.rb#L341

I was hoping rstrip_buffer! and a test for nuke_outer_whitespace could be used to eat the offending newline (before appending the next one), but it's not obvious (to me at the moment).

Also, modification might be required to more than the push_script method, because of the %tag= handling.. I think. And testing will be quite important, as changing anything this far inside the compiler might break things. (There are many calls to the *_merged_text methods ; the push_tag method is particularly lengthy.)

Happy to discuss with @norman, if there are any thoughts about it. It would be nice to fix it. OTOH, I'm not using HAML in any project at the moment, and I've never had this use-case. So I'm afraid I'm setting aside for now.

@jasonkuhrt

@richardkmichael Thanks for the update! Cheers to trying =)

@tonybruess

Any furthered progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.