css-class-string 0.0.4 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34a27b73b123c2df9943e743990632312e8d5409
4
- data.tar.gz: 79d2ed4e547d85e1b107793fdd8a4a7e753acad8
3
+ metadata.gz: b1c988b80cef43614f4950dd6f73c1c50ac5e955
4
+ data.tar.gz: 8ffa8dc1b370673035ff29eab1f3d26f351254fe
5
5
  SHA512:
6
- metadata.gz: 3d1fe5f9bf7193cfba0561e41807681c98582bcce5270a690ebeb17c0b36c772896a4ebd58fa4a17ff37ded70c6cd5a836a59410470e052657fc7be7ac591107
7
- data.tar.gz: d0e8f0611b0d3729cc62ea115fa25a576edff818a588c10ed485c87a1ede22a71b60f7b118e0200a82f2286aa6eee9cd11091788d079c9d69b750c82f12883b8
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(class_hash)
4
- @class_hash = class_hash
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
@@ -1,3 +1,3 @@
1
1
  module CssClassString
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,8 +2,8 @@ require "css_class_string/helper"
2
2
 
3
3
  module CssClassString
4
4
  module ViewHelpers
5
- def class_string(hash)
6
- ::CssClassString::Helper.new(hash).to_s
5
+ def class_string(*args)
6
+ ::CssClassString::Helper.new(*args).to_s
7
7
  end
8
8
  end
9
9
  end
@@ -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.0.4
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-06-11 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler