Chapter 12 - Haml Flashcards

1
Q

Create an Element

A

To create an HTML element in Haml, one simply needs to prefix the percent character (%) to an element name. The element name can be any string, allowing you to use newly added HTML5 elements, such as header.

%header content

content header >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Attributes

A

Attributes in Haml are defined using two styles. The first style involves defining attributes between curly braces ({}).

%a{ title: @article.title, href: article_path(@ article) } Title

%a( title=@article.title href = article_path(@article)) Title

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Haml Comment

A

-#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Evaluating Ruby code

A

Somewhat similar to ERb, using the equals character (=) results in Haml evaluating Ruby code following the character and outputting the result into the document.

%p = %w( foo bar). join(‘ ‘)

HTML foo bar p >

Alternatively, using the hyphen character (-) evaluates Ruby code but doesn’t insert its output into the resulting document. This is commonly used in combination with if/ else statements and loops.

  • if flash.notice.
    .notice= flash.notice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Interpolation

A

Ruby code can be interpolated in two ways in Haml: inline with plain text using #{} or using string interpolation in combination with =.

%p By: #{ post.author_name}

%p = “By: #{ post.author_name}”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly