SuperSnazzy Sneak Peak: Filters!

2 views
Skip to first unread message

Nathan Weizenbaum

unread,
Feb 3, 2007, 11:57:31 PM2/3/07
to ha...@googlegroups.com
Now, Haml is a wonderful language, but it's not meant for everything.
Obviously, stuff like CSS needs its own type of thing - that's why
there's Sass. But there are even some situations where HTML might need
more of a focus on the content and style than the structure. Then, a
human-friendly markup language like Textile or Markdown might be better
suited to the task than Haml. Unfortunately, these languages are most
often useful within a structure-oriented HTML document, like the kind
created by Haml. The only reasonable solution seems to be giving up and
painstakingly writing out all those <em>, <hx>, and <p> tags in Haml.

Not anymore! Haml has a new feature: filters. You can now embed another
parsing system right into your document. What was once

#script
%h2 Hamlet
%p
Where wilt thou lead me?
= succeed ';'
%em speak
I'll go no further.

%h2 Ghost
%p
%strong Mark me.

%h2 Hamlet
%p I will.

%h2 Ghost
%p
My hour is almost come,
When I to sulphurous and tormenting flames
Must render up myself.

%h2 Hamlet
%p Alas, poor ghost!

Now becomes

#script
:markdown
Hamlet
======

Where wilt thou lead me? *speak*; I'll go no further.

Ghost
=====

**Mark me.**

Hamlet
======

I will.

Ghost
=====

My hour is almost come,
When I to sulphurous and tormenting flames
Must render up myself.

Hamlet
======

Alas, poor ghost!

Far nicer, and easier to read.

Haml comes predefined with several filters, and has a simple interface
for defining your own. It comes with:

Markdown, Textile and Redcloth: Markdown and Textile are the human
markup languages with those names, and Redcloth is a combination of the
two. These are all only available if the Redcloth gem is installed, with
the exception of Markdown, which is also available if BlueCloth is
installed.

ERB: Uses ERB to parse the text.

Ruby: Runs the text through the Ruby interpreter, and outputs anything
from the text printed to standard output.

Sass: Sass. Duh.

Plain: Doesn't parse the text at all, just outputs it straight out. This
allows you to write text without worrying about stuff like "." or "%"
causing Haml to try to parse the line.

In the future, you may be able to pass instance variables to the
code-aware filters, like ERB and Ruby.

As usual, this feature is already implemented in trunk, so if you want
to try it out, all you have to do is download. Enjoy!

- Nathan

s.ross

unread,
Feb 8, 2007, 6:54:42 PM2/8/07
to ha...@googlegroups.com
Sorry about the odd title. Here's what I'm trying to accomplish:

!highlight_color = #5d3526

...

.line-below
:border-bottom= !highlight_color 1px solid

This will not, of course, work. Is there a Sassy way to accomplish this?

Thanks

Hampton

unread,
Feb 8, 2007, 7:46:59 PM2/8/07
to ha...@googlegroups.com
Its almost like you were listening in to me and Nathan's emails today.

We were discussing the exact same issue.

Hopefully, it will be possible soon....

Nathan Weizenbaum

unread,
Feb 9, 2007, 12:14:52 AM2/9/07
to ha...@googlegroups.com
When you use constants, you switch into constant-arithmetic mode, where
stuff like 4 + 5 evaluates to 9. Thus, you also need to use the "+"
operator to concatenate strings. If you want to include the spaces,
either do

:border-bottom= !highlight_color + \ 1px\ solid

or, more elegantly,

:border-bottom= !highlight_color + " 1px solid"

In the future, a lack of operator may default to concatenation with a space.

- Nathan

Reply all
Reply to author
Forward
0 new messages