css-class-string 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/README.md +6 -0
- data/css-class-string.gemspec +1 -0
- data/lib/css_class_string/helper.rb +19 -0
- data/lib/css_class_string/version.rb +1 -1
- data/lib/css_class_string/view_helpers.rb +3 -9
- data/spec/css_class_string/helper_spec.rb +40 -0
- data/spec/spec_helper.rb +78 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 087d76227ff9a92cd7ed27eb1ccdfb1b2972f99f
|
4
|
+
data.tar.gz: 826c3459f507ac8629e97daf80a65821cf07476c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c252d6ee17978b8757424e71cde5adcafc6736b89fa098ffb2489f05ead2e8ed571e49085c02ad2da608729bcad2ec5a3b69138389f861e5315aa41f668eae58
|
7
|
+
data.tar.gz: 4e2feb72c377a544c2c5010f8daa3d825ff81e9ab78fc8e4d96c400d64295782f37acec9c82464eb6732765c1a38564a8cc4240209c2a2a9b36f82a9bef6b831
|
data/.rspec
ADDED
data/README.md
CHANGED
data/css-class-string.gemspec
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module CssClassString
|
2
|
+
class Helper
|
3
|
+
def initialize(class_hash)
|
4
|
+
@class_hash = class_hash
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
@class_hash.inject({}) {|memo, (k, v)|
|
9
|
+
if k.is_a?(Array)
|
10
|
+
memo.merge({k[0] => v, k[1] => !v})
|
11
|
+
else
|
12
|
+
memo.merge({k => v})
|
13
|
+
end
|
14
|
+
}.map {|class_name, present|
|
15
|
+
class_name if present
|
16
|
+
}.compact.join(" ")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,15 +1,9 @@
|
|
1
|
+
require "css_class_string/helper"
|
2
|
+
|
1
3
|
module CssClassString
|
2
4
|
module ViewHelpers
|
3
5
|
def class_string(hash)
|
4
|
-
|
5
|
-
if k.is_a?(Array)
|
6
|
-
memo.merge({k[0] => v, k[1] => !v})
|
7
|
-
else
|
8
|
-
memo.merge({k => v})
|
9
|
-
end
|
10
|
-
}.map {|class_name, present|
|
11
|
-
class_name if present
|
12
|
-
}.join(" ")
|
6
|
+
::CssClassString::Helper.new(hash).to_s
|
13
7
|
end
|
14
8
|
end
|
15
9
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'css_class_string/view_helpers'
|
3
|
+
|
4
|
+
describe "CssClassString::Helper" do
|
5
|
+
describe ".to_s" do
|
6
|
+
|
7
|
+
context "when a key's value is truthy" do
|
8
|
+
let(:hash) { {truthy: true} }
|
9
|
+
subject { CssClassString::Helper.new(hash).to_s }
|
10
|
+
|
11
|
+
it { should eq("truthy") }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when a key's value is falsy" do
|
15
|
+
let(:hash) { {falsy: false} }
|
16
|
+
subject { CssClassString::Helper.new(hash).to_s }
|
17
|
+
|
18
|
+
it { should eq("") }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when a key is an array of two elements" do
|
22
|
+
|
23
|
+
context "when value is truthy" do
|
24
|
+
let(:hash) { {[:truthy, :falsy] => true} }
|
25
|
+
subject { CssClassString::Helper.new(hash).to_s }
|
26
|
+
|
27
|
+
it { should eq("truthy") }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when value is falsy" do
|
31
|
+
let(:hash) { {[:truthy, :falsy] => false} }
|
32
|
+
subject { CssClassString::Helper.new(hash).to_s }
|
33
|
+
|
34
|
+
it { should eq("falsy") }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
=begin
|
21
|
+
# These two settings work together to allow you to limit a spec run
|
22
|
+
# to individual examples or groups you care about by tagging them with
|
23
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
+
# get run.
|
25
|
+
config.filter_run :focus
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
|
28
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
+
# file, and it's useful to allow more verbose output when running an
|
30
|
+
# individual spec file.
|
31
|
+
if config.files_to_run.one?
|
32
|
+
# Use the documentation formatter for detailed output,
|
33
|
+
# unless a formatter has already been configured
|
34
|
+
# (e.g. via a command-line flag).
|
35
|
+
config.default_formatter = 'doc'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Print the 10 slowest examples and example groups at the
|
39
|
+
# end of the spec run, to help surface which specs are running
|
40
|
+
# particularly slow.
|
41
|
+
config.profile_examples = 10
|
42
|
+
|
43
|
+
# Run specs in random order to surface order dependencies. If you find an
|
44
|
+
# order dependency and want to debug it, you can fix the order by providing
|
45
|
+
# the seed, which is printed after each run.
|
46
|
+
# --seed 1234
|
47
|
+
config.order = :random
|
48
|
+
|
49
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
50
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
51
|
+
# test failures related to randomization by passing the same `--seed` value
|
52
|
+
# as the one that triggered the failure.
|
53
|
+
Kernel.srand config.seed
|
54
|
+
|
55
|
+
# rspec-expectations config goes here. You can use an alternate
|
56
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
57
|
+
# assertions if you prefer.
|
58
|
+
config.expect_with :rspec do |expectations|
|
59
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
60
|
+
# For more details, see:
|
61
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
expectations.syntax = :expect
|
63
|
+
end
|
64
|
+
|
65
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
66
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
67
|
+
config.mock_with :rspec do |mocks|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
+
mocks.syntax = :expect
|
72
|
+
|
73
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
74
|
+
# a real object. This is generally recommended.
|
75
|
+
mocks.verify_partial_doubles = true
|
76
|
+
end
|
77
|
+
=end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css-class-string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Rozhkov
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,6 +60,7 @@ extensions: []
|
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
62
|
- .gitignore
|
63
|
+
- .rspec
|
49
64
|
- Gemfile
|
50
65
|
- LICENSE.txt
|
51
66
|
- README.md
|
@@ -53,9 +68,12 @@ files:
|
|
53
68
|
- css-class-string.gemspec
|
54
69
|
- lib/css-class-string.rb
|
55
70
|
- lib/css_class_string.rb
|
71
|
+
- lib/css_class_string/helper.rb
|
56
72
|
- lib/css_class_string/railtie.rb
|
57
73
|
- lib/css_class_string/version.rb
|
58
74
|
- lib/css_class_string/view_helpers.rb
|
75
|
+
- spec/css_class_string/helper_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
59
77
|
homepage: https://github.com/nLight/css-class-string
|
60
78
|
licenses:
|
61
79
|
- MIT
|
@@ -80,4 +98,6 @@ rubygems_version: 2.0.5
|
|
80
98
|
signing_key:
|
81
99
|
specification_version: 4
|
82
100
|
summary: ''
|
83
|
-
test_files:
|
101
|
+
test_files:
|
102
|
+
- spec/css_class_string/helper_spec.rb
|
103
|
+
- spec/spec_helper.rb
|