Whitespace control

5 views
Skip to first unread message

Chris Yates

unread,
May 17, 2010, 7:46:34 AM5/17/10
to Haml Dev
Outer whitespace removal is "all or nothing" and I've had a few
instances with inline tags where that has given me a problem (OK, a
workaround is use to HTML, but this is a Haml file, right?)

A couple of examples:
1. Inline tag immediately following opening parenthesis
(
%a(href="url") Link
more text)

The desired result is "(Link more text)"

2. Comma separated list of links
%a(href="url1") Link1
,
%a(href="url2") Link2
,
%a(href="url3") Link3

The desired output is "Link1, Link2, Link3"

To enable the desired outputs, outer whitespace removal needs finer
control, i.e. remove only whitespace before or after the tag.

A solution I have come with is to allow modifiers to the outer
whitespace control
|> means remove outer whitespace, but not before the tag, only after
it
>| means remove outer whitespace, but not after the tag, only before it
> means remove all outer whitespace a sit does now.

I chose "|" as the modifier as it looks like a wall were you have to
stop.

Using the modifiers I can now get the output I want without resorting
to using inline HTML tags in Haml. The examples above become:
(
%a(href="url")>| Link
more text)

and
%a(href="url1")|> Link1
,
%a(href="url2")|> Link2
,
%a(href="url3")|> Link3

I hope this is of interest.



--
You received this message because you are subscribed to the Google Groups "Haml Dev" group.
To post to this group, send email to haml...@googlegroups.com.
To unsubscribe from this group, send email to haml-dev+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml-dev?hl=en.

Chris Eppstein

unread,
May 17, 2010, 1:17:01 PM5/17/10
to haml...@googlegroups.com, Haml Dev
Did you read this yet?

http://chriseppstein.github.com/blog/2010/02/08/haml-sucks-for-content/

Hunt & pecked on my iPhone... Sorry if it's brief!

On May 17, 2010, at 4:46 AM, Chris Yates <chris....@gmail.com>
wrote:

Nathan Weizenbaum

unread,
May 17, 2010, 1:18:58 PM5/17/10
to haml...@googlegroups.com
This is definitely a hole in the Haml syntax, but I'm always nervous about adding new syntax. In general, we do advise using plain HTML for such cases; putting commas on their own line will always look a little silly (see the blog post Chris linked).

The way Ruby Haml deals with this is to provide two helper methods, #precede and #succeed, which basically accomplish what |> and >| do in your example. The functions are a pain to use, but the idea is that most of the time you should be using inline HTML instead. I kind of lean towards using something like that rather than adding even more syntax.

Chris Yates

unread,
May 18, 2010, 3:46:42 AM5/18/10
to Haml Dev
Thanks for the replies.Interesting post from Chris - will add a link
to that

On May 17, 6:18 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:
> This is definitely a hole in the Haml syntax, but I'm always nervous about
> adding new syntax. In general, we do advise using plain HTML for such cases;
> putting commas on their own line will always look a little silly (see the
> blog post Chris linked).
>
> The way Ruby Haml deals with this is to provide two helper methods, #precede
> and #succeed, which basically accomplish what |> and >| do in your example.
> The functions are a pain to use, but the idea is that most of the time you
> should be using inline HTML instead. I kind of lean towards using something
> like that rather than adding even more syntax.
>
> > haml-dev+u...@googlegroups.com<haml-dev%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/haml-dev?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Haml Dev" group.
> To post to this group, send email to haml...@googlegroups.com.
> To unsubscribe from this group, send email to haml-dev+u...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/haml-dev?hl=en.
Reply all
Reply to author
Forward
0 new messages