List Info

Thread: haml, inline list items (li's) and suppressing line breaks




haml, inline list items (li's) and suppressing line breaks
country flaguser name
United States
2007-10-16 15:15:50
Is there a way to suppress line breaks in haml?

So let's say you've got an inline list you're using as a
horizontal
menubar.

%ul
  %li one
  %li two
  %li three

resulting in

<pre>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</pre>

Well, what you really want is
<pre>
<ul>
<li>one</li><li>two</li><li>th
ree</li>
</ul>
</pre>

because Firefox and Safari treat line breaks between inline
elements
as spaces. So in ie the items are adjacent to eachother, and
in other
browsers there exists a space between each element.

It would be great to have something like a - (dash)
character at the
end of a line that indicates to haml that it should not
render a
newline before rendering the next element.

Or have I spaced out an missed a similar feature in the
doco?

Thanks for taking the time to read this. A true whitespace
snob I am.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: haml, inline list items (li's) and suppressing line breaks
country flaguser name
United States
2007-10-16 19:35:33
We're all whitespace snobs here .

This is really the one major inability of Haml that still
exists. 
Currently, no language feature exists to specify that you
don't want 
whitespace. This will be fixed by version 2.0, but currently
no such fix 
exists.

I think the best solution for the time being is writing a
helper (this 
may actually be what we end up doing in the end). Something
like

  def strip_whitespace(&haml)
    capture_haml(&haml).gsub(s*(<|>)s*, '1')
  end

which you would then call with

  %ul
    = strip_whitespace do
      %li one
      %li two
      %li three

Note that that helper is totally untested and may not work
at all. But 
with some tweaking it should be fine.

- Nathan

tshim wrote:
> Is there a way to suppress line breaks in haml?
>
> So let's say you've got an inline list you're using as
a horizontal
> menubar.
>
> %ul
>   %li one
>   %li two
>   %li three
>
> resulting in
>
> <pre>
> <ul>
> <li>one</li>
> <li>two</li>
> <li>three</li>
> </ul>
> </pre>
>
> Well, what you really want is
> <pre>
> <ul>
>
<li>one</li><li>two</li><li>th
ree</li>
> </ul>
> </pre>
>
> because Firefox and Safari treat line breaks between
inline elements
> as spaces. So in ie the items are adjacent to
eachother, and in other
> browsers there exists a space between each element.
>
> It would be great to have something like a - (dash)
character at the
> end of a line that indicates to haml that it should not
render a
> newline before rendering the next element.
>
> Or have I spaced out an missed a similar feature in the
doco?
>
> Thanks for taking the time to read this. A true
whitespace snob I am.
>
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )