css-class-string 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/css_class_string/helper.rb +4 -2
- data/lib/css_class_string/version.rb +1 -1
- data/lib/css_class_string/view_helpers.rb +2 -2
- data/spec/css_class_string/helper_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1c988b80cef43614f4950dd6f73c1c50ac5e955
|
4
|
+
data.tar.gz: 8ffa8dc1b370673035ff29eab1f3d26f351254fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6491477be1bd1d024af520cfa54a8c40c057acd6fd814493f9a61b7a66e9486deaec60de89d93782c97ed44477abe11e3f655afe0d2d934e19810bf5b2dcc5f
|
7
|
+
data.tar.gz: 5a98b546145661ac67fc6738e0ab8fc758d319e0791d88a4a9c1c63ae2b3fb20381e5b17083425710fd809cd239bde4127a0525cc0856417dde6e83695bb5df1
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Helper for creating css class strings inspired by ReactJS classSet
|
4
4
|
|
5
|
+
- Pass bare arguments for default classes
|
6
|
+
- Pass hash of `class => <boolean>` for conditional classes
|
7
|
+
- Use array with two classes as a `key` and first will be used for truthy and second for falsey value `[:true?, :false?] => <boolean>`
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -13,12 +17,16 @@ Add this line to your application's Gemfile:
|
|
13
17
|
```haml
|
14
18
|
// @boolvalue = true
|
15
19
|
%span{class: class_string({some: true, classy: false, [:truthy, :falsy] => @boolvalue})}
|
20
|
+
// equal to
|
21
|
+
%span{class: class_string('some', falsy: false, [:truthy, :falsy] => @boolvalue)}
|
16
22
|
// => <span class="some truthy"></span>
|
17
23
|
```
|
18
24
|
|
19
25
|
```html+erb
|
20
26
|
<!-- @boolvalue = false -->
|
21
27
|
<span class="<%= class_string({some: true, classy: true, [:truthy, :falsy] => @boolvalue} %>">
|
28
|
+
<!-- equal to -->
|
29
|
+
<span class="<%= class_string('some', 'classy', [:truthy, :falsy] => @boolvalue %>">
|
22
30
|
<!-- => <span class="some classy falsy"></span> -->
|
23
31
|
```
|
24
32
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module CssClassString
|
2
2
|
class Helper
|
3
|
-
def initialize(
|
4
|
-
|
3
|
+
def initialize(*args)
|
4
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
5
|
+
@class_hash = args.map {|class_name| { class_name => true }}.reduce({}, &:merge)
|
6
|
+
@class_hash.merge!(options)
|
5
7
|
end
|
6
8
|
|
7
9
|
def to_s
|
@@ -53,5 +53,15 @@ describe "CssClassString::Helper" do
|
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
+
context 'with truthy arguments only' do
|
57
|
+
subject { CssClassString::Helper.new('truthy_1', 'truthy_2').to_s }
|
58
|
+
it { is_expected.to eq('truthy_1 truthy_2') }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with mixed arguments' do
|
62
|
+
subject { CssClassString::Helper.new('truthy_1', 'truthy_2', falsy: false, truthy_3: true).to_s }
|
63
|
+
it { is_expected.to eq('truthy_1 truthy_2 truthy_3') }
|
64
|
+
end
|
65
|
+
|
56
66
|
end
|
57
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css-class-string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Rozhkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|