Hamlet is a template language whose goal is to reduce HTML syntax to the essential parts.
<body>
<p>Some paragraph.
<ul data-attr=list>
<li>Item 1
<li>Item 2
That Hamlet snippet is equivalent to:
<body>
<p>Some paragraph.</p>
<ul data-attr="list">
<li>Item 1</li>
<li>Item 2</li>
</ul>
</body>
see, it is just HTML! Designers love Hamlet because it is just HTML! Closing tags are inferred from whitespace.
You can see the original Haskell hamlet templating language and the [javascript port](hamlet: https://github.com/gregwebs/hamlet.js).
This Hamlet (ruby) works on top of slim. Please take a look at the slim documentation if you are looking to see if a more advanced feature is supported.
The most important difference is that hamlet always uses angle brackets. Hamlet also does not require attributes to be quoted - unquoted is considered a normal html attribute value and quotes will automatically be added. Hamlet also uses a '#' for code comments and the normal <!-- for HTML comments. Hamlet also uses different whitespace indicators - see the next section.
In Slim you have:
/! HTML comment
p data-attr="foo" Text
| More Text
/ Comment
In hamlet you have:
<!-- HTML comment
<p data-attr=foo>Text
More Text
# Comment
Using indentation does have some consequences with respect to white space. This library is designed to do the right thing most of the time. This is a slightly different design from the original Haskell implementation of Hamlet and Slim, but the same design as hamlet.js
A closing tag is placed immediately after the tag contents. If you want to have a space before a closing tag, use a comment sign #
on the line to indicate where the end of the line is.
<b>spaces # 2 spaces are included
A new line is automatically added after tags with inner text. If you have multiple lines of inner text without tags (not a common use case) they will also get a new line added. If you do not want white space, you point it out with a >
character, that you could think of as the end of the last tag, although you can still use it when separating content without tags onto different lines. You can also use a >
if you want more than one space.
<b>spaces # 2 spaces are included
<b>spaces </b>
<b>no space
>none after bold.
> Two spaces after a period is bad!
<b>no space</b>none after bold. Two spaces after a period is bad!
You can hook up i18n support the same way you would for other templating lanugages. This rails plugin works out of the box.
A space is not automatically added after a tag when looping through an array
Double quotes in attributes will get messed up: click=do('ok!')
not click=do("whoops!")
Run tests with
bundle exec rake test
or
bundle exec ruby -r ./test/slim/helper.rb TEST
There are some failing tests that are skipped right now