views:

19

answers:

0

To generate <span> or inline elements using a loop, so that the result has no white space between them:

%div
  - 5.times do
    %span> hello

the above will create

<div><span>hello</span><span>hello</span><span>hello</span><span>hello</span><span>hello</span></div>

(practically, it is no use to stick "hello" together, but say, if we generate 5 <img> tags and not want any space or newline in between)

but what if the div has a long line of attributes and we want to put on the next line all by itself, like this:

<div>
    <span>hello</span><span>hello</span><span>hello</span><span>hello</span><span>hello</span>
</div>

the above should not affect the display on screen at all, because only the white space between inline elements are shown, not outside.

but to create the HTML above, isn't the HAML a bit clumsy that we have to special case the first and last case in the loop to make it

%div
  - 1.upto(5)
    - if (i == 1 or i == 5)
      %span hello
    - else
      %span> hello

? is there another way not needing special cases? (actually, the above won't exactly generate the desired outcome, which I will post in another question).