"~" had two different functions. First, it could be used as an
alternative to "=" that would replace all newlines in
whitespace-sensitive tags such as <pre> and <textarea> with the HTML
characters for newlines, thus preserving both whitespace /and/ style.
This function can now be done literally with a function:
find_and_preserve. For example, what was once:
~ text_area :user, :profile
becomes
= find_and_preserve(text_area :user, :profile)
There's also another, related helper function, just called "preserve",
that removes all newlines period, without regard for what tag is where.
The second function was to precede a nested block of text, which would
ensure that all whitespace in that text was preserved. The idea of doing
stuff with nested blocks of text might sound a lot like filters to
you... and it does to us, too, which is why we're replacing that
function with an actual filter. The "preserve" filter serves the same
purpose as the "~" on its own. For instance, what was
%pre
~
1
2
3
4
is now
%pre
:preserve
1
2
3
4
The "~" command will still be around, although undocumented, as of the
next release of Haml (1.5). If you use it, Haml will spit out a warning,
but it will work. However, in the release after 1.5, it will be gone for
good, so update your views as soon as possible.
You may be wondering why we're deprecating this at all. "Sure, Nathan,
it's like a filter," you say, "but is it really worth it to get rid of
it altogether?" Well, if you were to ask this, I would reply that yes,
yes it is worth it. There are several reasons to get rid of this:
1. It cluttered up the code. Checking for preserved text necessitated
more than its fair share of logic precisely where we wanted the
least logic. When we do eventually remove it, the code will become
much neater.
2. It was redundant. Everything it did could, and probably should,
have been done with filters or helpers.
3. It cluttered up Haml. Haml aims to be simple and easy to learn,
and having lots of obscure commands doesn't help that at all. This
is particularly true when the commands intuitively seem like they
should be something other than commands (see point 2).
We don't like deprecating stuff, and this is probably the only thing
we'll be deprecating in a good while, so don't worry about your views
breaking beyond this (if you use this... how many of you folks even knew
this command existed?).
- Nathan
I think I should be able to say:
= textarea :user, :profile
and get the same result as is currently returned by
~ textarea :user, :profile
The new methods may improve the haml source code, but from my
perspective as a user, they don't improve ease of use or readiblity of
my code.
Thanks,
-- Jeff
On Feb 6, 3:30 am, Nathan Weizenbaum <nex...@gmail.com> wrote:
> That's right, folks, Haml is deprecating one of its commands: the
> (apparently little-known) "~". Once useful for allowing people to create
> whitespace-sensitive blocks of text inline, and styliciously handling
> <textarea> and <pre> tags, "~" is now more or less rendered redundant
> with the introduction of filters
> (http://groups.google.com/group/haml/browse_thread/thread/5ed706013a47...)
= <an expression>
to behave exactly the same way no matter what follows it. What would
be surprising is if somewhere along the line that behavior changed on
a case by case basis.
Just my $.02.
As to readability, I think having an obscure command, such as "~", or
worse yet no command at all, is much less readable than a clearly-named
helper method.
- Nathan
And I still use it.
-hampton
- Nathan
IMHO, textarea is not a "case that doesn't come up at all for most
people". It comes up for everyone who creates a form.
Ross argues for maintaining the integrity of haml the template
langauge. When I suggested special behavior for textarea and pre, I
was arguing for maintaining the integrity of the markup that haml
produces.
I love haml and I can live with the deprecation, but I don't buy the
arguments. ~ is no more obscure than %, - or find_and_preserve.
-- Jeff
on a side note, can someone explain the logic behind the name
find_and_preserve ? --- what are we finding ?
It finds whitespace sensitive elements <pre>, <textarea>, and a few
others... when it finds one... it takes the contents of the area and
then converts \n into the HTML entity for endline. That way...
basically multi-line things *look* like single lines that be browser
treats as having endlines. It used be be called "find_and_flatten".
%textarea
I'm
here
becomes
<textarea>I'm&ENTITYICANTREMEMBERhere</textarea>
That way when later Haml templates get the area, they can indent
freely, since there aren't any \ns.... The browser treats them the
same.
Its basically a hack that allows us to have whitespace sensitive areas
on the page and still have it look pretty when we indent it properly.
-hampton.
"~" is more obscure than "%" or "-" because it's not commonly used. The
largest number of questions I heard about Haml when it was first
released were, "I get =, but what does ~ do?" For a long time we've been
getting people saying "My whitespace doesn't work!" Even though this
command is fully documented in the reference, people didn't know it
existed. The difference between "%" and "-" is that both of those are
fundamental to the functionality of Haml... "~" was not.
By changing it to find_and_preserve, we've done two things. First, we've
linked it into the existing Helper functionality, which is (hopefully) a
place people look for solutions to these problems. Second, we've made
the name very descriptive, unlike "~", which doesn't convey any meaning
at all.
- Nathan
- Nathan
JR
-hampton.
Can we list all situations where we commonly use preserve? Is it
restricted to only textarea and pre ? Or are their other (common)
reasons?
weepy
On Feb 12, 2:08 am, Hampton <hcat...@gmail.com> wrote:
> Every site I build uses it at least 2-4 times.
>
> -hampton.
>
- Nathan
- Nathan
My point is that it IS the expected behavior for textarea, pre and
code tags. That's why newbies write to you saying "my whitespace
doesn't work". That's why newbies don't use the "~" in the first
place, because they think "=" should work.
That being said, I'll agree that it is reasonable to demand that those
tags be treated as special cases. However "find_and_preserve" is not
very descriptive or elegant. And while "~" is not particularly
descriptive, it is IMHO elegant.
If I understood your previous posts in this thread, there are valid
software engineering issues which make the deprecation a good idea.
But as a user, the arguments that "it's better for you" and "it
shouldn't matter to you" ring false.
Regards,
Jeff
- Nathan