Read more

Know your Haml comments

Arne Hartherz
September 08, 2010Software engineer at makandra GmbH

There are two distinct ways of commenting Haml markup: HTML and Ruby.

HTML comments

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

This will create an HTML comment that will be sent to the client (aka browser):

/= link_to 'Example', 'www.example.com'

This produces the following HTML:

<!-- = link_to 'Example', 'www.example.com' -->

Only use this variant if you need the comment to appear in the HTML.

Ruby comments

This will comment code so it will not be sent to the client:

-# = link_to 'foo'

99% of the time you'll be adding notes for other developers, or disabling code sections that should not be sent to the client.

Prefer using -# (which is actually: - "start a Ruby block" + # "Ruby comment").

Warning

This type of comments needs to be indented properly. If you get a syntax error (sometimes a very unhelpful one, echoing the whole file without giving a specific line number), don't forget to check the comments.

Posted by Arne Hartherz to makandra dev (2010-09-08 21:02)