Matthew Rudy
Matthew Rudy

Reputation: 16834

How do I trim all whitespace in HAML?

In my example I want to individually markup letters in the word "word"

%span.word
  %span.w W
  %span.o O
  %span.r R
  %span.d D

As it is, this produces html like

<span class="word">
  <span class="w">W</span>
  <span class="o">O</span>
  <span class="r">R</span>
  <span class="d">D</span>
</span>

As you'd expect this displays as

W O R D

But I want it to display as

WORD

How can tell haml to remove all whitespace within the %span.word block?

Upvotes: 3

Views: 1497

Answers (2)

hlomas
hlomas

Reputation: 21

http://haml.info/docs/yardoc/Haml/Options.html#remove_whitespace-instance_method

HAML allows you set a remove_whitespace option which will remove whitespace from all tags, if you don't want to litter your templates with < and > everywhere.

Upvotes: 1

jdoe
jdoe

Reputation: 15771

%span.word
  %span.w> W
  %span.o> O
  %span.r> R
  %span.d> D

> (for whitespaces around a tag) and < (for whitespaces inside a tag) are used for whitespace removal.

Upvotes: 10

Related Questions