2006-12-19 02:56:49 +00:00
|
|
|
= Haml and Sass
|
2006-06-30 15:14:44 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
Haml and Sass are templating engines
|
|
|
|
for the two most common types of documents on the web:
|
|
|
|
HTML and CSS, respectively.
|
|
|
|
They are designed to make it both easier and more pleasant
|
2007-01-02 07:45:29 +00:00
|
|
|
to code HTML and CSS documents,
|
2006-12-19 02:56:49 +00:00
|
|
|
by eliminating redundancy,
|
|
|
|
reflecting the underlying structure that the document represents,
|
|
|
|
and providing elegant, easily understandable, and powerful syntax.
|
2006-09-12 13:54:22 +00:00
|
|
|
|
2006-09-12 13:05:28 +00:00
|
|
|
== Formatting
|
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
=== Haml
|
2006-11-04 06:36:16 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
The most basic element of Haml
|
|
|
|
is a shorthand for creating HTML tags:
|
2006-11-04 06:36:16 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
%tagname{ :attr1 => 'value1', :attr2 => 'value2' } Contents
|
2006-11-04 06:36:16 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
No end-tag is needed; Haml handles that automatically.
|
|
|
|
Adding <tt>class</tt> and <tt>id</tt> attributes is even easier.
|
|
|
|
Haml uses the same syntax as the CSS that styles the document:
|
2006-10-27 20:36:34 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
%tagname#id.class
|
2006-11-04 06:36:16 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
In fact, when you're using the <tt><div></tt> tag,
|
|
|
|
it becomes <em>even easier</em>.
|
|
|
|
Because <tt><div></tt> is such a common element,
|
|
|
|
a tag without a name defaults to a div. So
|
2006-10-27 20:36:34 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
#foo Hello!
|
2006-11-04 06:36:16 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
becomes
|
2006-11-06 00:35:38 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
<div id='foo'>Hello!</foo>
|
|
|
|
|
|
|
|
Haml uses indentation
|
|
|
|
to bring the individual elements to represent the HTML structure.
|
|
|
|
A tag's children are indented two spaces more than the parent tag.
|
|
|
|
Again, a closing tag is automatically added.
|
2006-11-14 01:58:55 +00:00
|
|
|
For example:
|
2006-10-14 22:24:53 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
%ul
|
|
|
|
%li Salt
|
|
|
|
%li Pepper
|
2006-10-14 22:24:53 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
becomes:
|
2006-10-22 21:42:45 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
<ul>
|
|
|
|
<li>Salt</li>
|
|
|
|
<li>Pepper</li>
|
|
|
|
</ul>
|
2006-11-17 01:12:50 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
You can also put plain text as a child of an element:
|
2006-10-14 22:24:53 +00:00
|
|
|
|
|
|
|
%p
|
2006-12-19 02:56:49 +00:00
|
|
|
Hello,
|
|
|
|
World!
|
2006-11-18 09:48:34 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
It's even possible to embed Ruby code into Haml documents.
|
|
|
|
An equals sign, <tt>=</tt>, will output the result of the code.
|
|
|
|
A hyphen, <tt>-</tt>, will run the code but not output the result.
|
|
|
|
You can even use control statements
|
|
|
|
like <tt>if</tt> and <tt>while</tt>:
|
2006-10-14 22:24:53 +00:00
|
|
|
|
|
|
|
%p
|
2006-12-19 02:56:49 +00:00
|
|
|
Date/Time:
|
|
|
|
- now = DateTime.now
|
|
|
|
%strong= now
|
|
|
|
- if now > DateTime.parse("December 31, 2006")
|
|
|
|
= "Happy new " + "year!"
|
2006-09-12 13:05:28 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
Haml provides far more tools than those presented here.
|
|
|
|
Check out the reference documentation in the Haml module.
|
2006-09-10 17:02:52 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
=== Sass
|
2006-11-04 06:36:16 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
*add docs*
|
2006-09-10 17:02:52 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
== Authors
|
2006-09-10 17:02:52 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
Haml and Sass are designed by Hampton Catlin (hcatlin).
|
|
|
|
Help with the Ruby On Rails implementation and much of the documentation
|
|
|
|
by Jeff Hardy (packagethief).
|
2006-09-10 17:02:52 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
Nathan Weizenbaum (Nex3) contributed the buffered-engine code to Haml,
|
|
|
|
along with many other enhancements
|
|
|
|
(including the silent-line syntax: "-").
|
|
|
|
He continues to actively work on both Haml and Sass.
|
2006-11-04 08:35:06 +00:00
|
|
|
|
2006-12-19 02:56:49 +00:00
|
|
|
If you use this software, you must pay Hampton a compliment.
|
|
|
|
Say something nice about it.
|
|
|
|
Beyond that, the implementation is licensed under the MIT License.
|
|
|
|
Ok, fine, I guess that means compliments aren't *required*.
|