@@ -6,33 +6,33 @@ This is a view helper that dynamically generates class attributes in Rails view,
6
6
The Helper method is included automatically, so you can use it immediately.
7
7
8
8
``` erb
9
- <div class="<%= classNames ('foo') %>">Hello World</div>
9
+ <div class="<%= class_names ('foo') %>">Hello World</div>
10
10
<%# <div class="foo">Hello World</div> %>
11
11
```
12
12
13
- The ` classNames ` method takes any number of arguments which can be a string or hash.
13
+ The ` class_names ` method takes any number of arguments which can be a string or hash.
14
14
The argument ` 'foo' ` is short for ` { foo: true } ` . If the value associated with a given key is falsy, that key won't be included in the output.
15
15
16
16
``` js
17
- classNames (' foo' , ' bar' ); // => 'foo bar'
18
- classNames (' foo' , { bar: true }); // => 'foo bar'
19
- classNames ({ ' foo-bar' : true }); // => 'foo-bar'
20
- classNames ({ ' foo-bar' : false }); // => ''
21
- classNames ({ foo: true }, { bar: true }); // => 'foo bar'
22
- classNames ({ foo: true , bar: true }); // => 'foo bar'
17
+ class_names (' foo' , ' bar' ); // => 'foo bar'
18
+ class_names (' foo' , { bar: true }); // => 'foo bar'
19
+ class_names ({ ' foo-bar' : true }); // => 'foo-bar'
20
+ class_names ({ ' foo-bar' : false }); // => ''
21
+ class_names ({ foo: true }, { bar: true }); // => 'foo bar'
22
+ class_names ({ foo: true , bar: true }); // => 'foo bar'
23
23
24
24
// lots of arguments of various types
25
- classNames (' foo' , { bar: true , duck: false }, ' baz' , { quux: true }); // => 'foo bar baz quux'
25
+ class_names (' foo' , { bar: true , duck: false }, ' baz' , { quux: true }); // => 'foo bar baz quux'
26
26
27
27
// other falsy values are just ignored
28
- classNames (null , false , ' bar' , undefined , 0 , 1 , { baz: null }, ' ' ); // => 'bar 1'
28
+ class_names (null , false , ' bar' , undefined , 0 , 1 , { baz: null }, ' ' ); // => 'bar 1'
29
29
```
30
30
31
31
Arrays will be recursively flattened as per the rules above:
32
32
33
33
``` js
34
34
var arr = [' b' , { c: true , d: false }];
35
- classNames (' a' , arr); // => 'a b c'
35
+ class_names (' a' , arr); // => 'a b c'
36
36
```
37
37
38
38
### Change the method name
0 commit comments