Skip to content

Commit cccf353

Browse files
committed
boolean
1 parent a86adc8 commit cccf353

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ In Theo, an attribute with computed value can be expressed using `%=`. For examp
5555
```html
5656
<a href%="root_path">Home</a>
5757
```
58-
is roughly equivalent[\*](#erasing-falsy-attributes) to:
58+
is equivalent to:
5959
```erb
6060
<a href="<%= root_path %>">Home</a>
6161
```
@@ -79,17 +79,17 @@ which in turn is equivalent to:
7979
<img src="<%= src %>">
8080
```
8181

82-
#### <a id="erasing-failsy-attributes"></a>Erasing falsy attributes from HTML tags
82+
#### Boolean HTML attributes
8383

84-
If value of attribute is falsy (`false` or `nil`), then it will be omitted from the resulting markup. This is achieved by wrapping each attribute in a condition.
84+
Some standard HTML attributes, such as `disabled`, `required` or `checked`, are boolean, which means that they have a `true` value when they're present and a `false` value when they're not. If value of such attribute is falsy (`false` or `nil`), then it will be omitted from the resulting markup, otherwise an empty attribute will be included.
8585

8686
For example:
8787
```html
88-
<input name="login" disabled%>
88+
<input name="login" disabled%="can_login">
8989
```
9090
is equivalent to:
9191
```erb
92-
<input name="login" <% if (_val = disabled) %>disabled="<%= _val %>"<% end %>>
92+
<input name="login" <% if can_login %>disabled<% end %>>
9393
```
9494

9595
> [!NOTE]
@@ -128,7 +128,9 @@ Naturally, partials can also include content, e.g.:
128128
129129
#### Boolean partial attributes
130130

131-
If a partial attribute has no value, you can omit it, for example:
131+
If a partial attribute value is not important and it only matters whether it's `truthy` or `falsy`, you can omit it.
132+
133+
For example:
132134
```html
133135
<_button disabled />
134136
```

0 commit comments

Comments
 (0)