You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: haml-style-guide.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
##HAML best practices
1
+
# HAML Styleguide
2
2
3
3
Because of the importance indentation has on how your code is rendered, the indents should be consistent throughout the document. Any differences in indentation will throw an error. It's common-practice to use two spaces.
4
4
5
-
###How to use HTML elements
5
+
## How to use HTML elements
6
6
7
7
To write your tags, use the percent sign followed by the name of the tag
8
8
@@ -30,7 +30,7 @@ If you want to add multiple classes, simply chain them:
30
30
.container.large.unobtrusive
31
31
```
32
32
33
-
###How to use comments
33
+
## How to use comments
34
34
35
35
There’re three different styles to write comments in Haml.
36
36
@@ -56,11 +56,11 @@ There’re three different styles to write comments in Haml.
56
56
57
57
**Note:** Single and multiline comments will be redenred into the document. Therefore we commonly choose the third option because usually comments are meant for developers only.
58
58
59
-
###Use blocks
59
+
## Use blocks
60
60
61
61
HAML isn’t Ruby, but it still incorporates some convenient elements of it, and there’s no better example of that than the block syntax.
62
62
63
-
####Morph code into block format with `precede`, `succeed` and `surround`
63
+
### Morph code into block format with `precede`, `succeed` and `surround`
64
64
65
65
**Example:**
66
66
@@ -93,7 +93,7 @@ Using inline HTML and `content_tag`
93
93
94
94
This isn’t terrible, but the above blocks are much more readable!
95
95
96
-
####Use `link_to` as a block
96
+
### Use `link_to` as a block
97
97
98
98
When wrapping long or multiple elements in a link tag, It’s wise to use `link_to` in block format.
99
99
@@ -125,7 +125,7 @@ Rails routing is best used with its built-in helper methods, where objects can b
125
125
%a{href: users_path(@user)} View User Profile
126
126
```
127
127
128
-
####Use `list_of`
128
+
### Use `list_of`
129
129
130
130
A lesser known – and thus, lesser used – feature of HAML is `list_of`.
131
131
This method generates * elements for you as you iterate over a list of items.
@@ -158,7 +158,7 @@ Whitespace abuse. Every time you use `list_of`, you’ve saved one indentation.
158
158
= link_to student.name, [course, student]
159
159
```
160
160
161
-
###Use filters
161
+
## Use filters
162
162
163
163
Use the colon to define [Haml filters](http://haml.info/docs/yardoc/file.REFERENCE.html#filters). This allows you to pass an indented block of text as input to another filtering program and add the result to the output of Haml.
164
164
@@ -176,7 +176,7 @@ Use the colon to define [Haml filters](http://haml.info/docs/yardoc/file.REFEREN
176
176
console.log('This is inline script');
177
177
```
178
178
179
-
###Use curly braces
179
+
## Use curly braces
180
180
181
181
The name of the game here is readability and a big part of readability is DRY.
182
182
@@ -206,7 +206,7 @@ Note that you can also pass in hashes directly into the data attribute, and it w
At this point, you know exactly what `-` and `=` do in your HAML views, but what about the other fun Ruby expression outputting methods? These alternative outputting methods have got to be some of the most underused features of HAML, yet is one of the most useful, especially for internal communication.
212
212
@@ -256,6 +256,6 @@ When you don’t know about interpolated Ruby code, you’re bound to pull this
256
256
257
257
Don’t bother with these strings – just cut right into the interpolated input expressed above and save characters and eye strain.
0 commit comments