class_names 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +66 -0
- data/.rubocop.yml +89 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/README.md +64 -0
- data/Rakefile +10 -0
- data/class_names.gemspec +30 -0
- data/lib/class_names.rb +2 -0
- data/lib/class_names/helper.rb +28 -0
- data/lib/class_names/railtie.rb +9 -0
- data/lib/class_names/version.rb +3 -0
- data/lib/class_names/view_helper.rb +9 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7252ad0407a66b839b7b9b81c5477780bdb3e9a57646c2bd055664cc5ba4f446
|
4
|
+
data.tar.gz: 59e5438cfc0fbed29c787cdaad64c1dbd5092ddd6115165125966a1321bbe8ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc6d44a8725469c947a5888c29dd908d06073b7911e81de1ace8b9d04cc7e28445fb567b0c0d52e972280a9c76962f86509810563dac82114a4152a2cf199971
|
7
|
+
data.tar.gz: 366c3e7ac44d147ccd1080460b67eb06c9124b1bb6e5f7f4ead6b9336f56b62e7046b1df2529a9d34d0dffa26654f2002a8ca5bc8ce29276eede062c6dc6e032
|
data/.gitignore
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
### Ruby template
|
10
|
+
*.gem
|
11
|
+
*.rbc
|
12
|
+
/.config
|
13
|
+
/coverage/
|
14
|
+
/InstalledFiles
|
15
|
+
/pkg/
|
16
|
+
/spec/reports/
|
17
|
+
/spec/examples.txt
|
18
|
+
/test/tmp/
|
19
|
+
/test/version_tmp/
|
20
|
+
/tmp/
|
21
|
+
|
22
|
+
# Used by dotenv library to load environment variables.
|
23
|
+
# .env
|
24
|
+
|
25
|
+
# Ignore Byebug command history file.
|
26
|
+
.byebug_history
|
27
|
+
|
28
|
+
## Specific to RubyMotion:
|
29
|
+
.dat*
|
30
|
+
.repl_history
|
31
|
+
build/
|
32
|
+
*.bridgesupport
|
33
|
+
build-iPhoneOS/
|
34
|
+
build-iPhoneSimulator/
|
35
|
+
|
36
|
+
## Specific to RubyMotion (use of CocoaPods):
|
37
|
+
#
|
38
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
39
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
40
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
41
|
+
#
|
42
|
+
# vendor/Pods/
|
43
|
+
|
44
|
+
## Documentation cache and generated files:
|
45
|
+
/.yardoc/
|
46
|
+
/_yardoc/
|
47
|
+
/doc/
|
48
|
+
/rdoc/
|
49
|
+
|
50
|
+
## Environment normalization:
|
51
|
+
/.bundle/
|
52
|
+
/vendor/bundle
|
53
|
+
/lib/bundler/man/
|
54
|
+
|
55
|
+
# for a library or gem, you might want to ignore these files since the code is
|
56
|
+
# intended to run in multiple environments; otherwise, check them in:
|
57
|
+
# Gemfile.lock
|
58
|
+
# .ruby-version
|
59
|
+
# .ruby-gemset
|
60
|
+
|
61
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
62
|
+
.rvmrc
|
63
|
+
|
64
|
+
### JetBrains template
|
65
|
+
.idea/
|
66
|
+
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rails
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.3
|
7
|
+
TargetRailsVersion: 4.2
|
8
|
+
Exclude:
|
9
|
+
- db/schema.rb
|
10
|
+
- 'vendor/**/*'
|
11
|
+
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 125
|
14
|
+
|
15
|
+
Style/RaiseArgs:
|
16
|
+
EnforcedStyle: compact
|
17
|
+
|
18
|
+
# Wants us to use %w or %W for arrays of strings
|
19
|
+
Style/WordArray:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Adds Rails linting suggestions
|
23
|
+
Rails:
|
24
|
+
Enabled: true
|
25
|
+
|
26
|
+
# Double quotes > single quotes
|
27
|
+
Style/StringLiterals:
|
28
|
+
EnforcedStyle: double_quotes
|
29
|
+
|
30
|
+
# Explicit return at the end of a method helps with readability
|
31
|
+
Style/RedundantReturn:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
# We don't usually want to separate our ints with '_' for readability
|
35
|
+
Style/NumericLiterals:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
# This is a weird suggested syntax, and not as readable
|
39
|
+
ConditionalAssignment:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/RedundantSelf:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/NegatedIf:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/SymbolArray:
|
49
|
+
EnforcedStyle: brackets
|
50
|
+
|
51
|
+
Metrics/MethodLength:
|
52
|
+
Max: 30
|
53
|
+
Exclude:
|
54
|
+
- "db/**/*"
|
55
|
+
|
56
|
+
ClassLength:
|
57
|
+
Max: 500
|
58
|
+
|
59
|
+
Metrics/ModuleLength:
|
60
|
+
Max: 500
|
61
|
+
|
62
|
+
Style/ClassAndModuleChildren:
|
63
|
+
EnforcedStyle: compact
|
64
|
+
|
65
|
+
Style/ReturnNil:
|
66
|
+
Enabled: true
|
67
|
+
EnforcedStyle: return_nil
|
68
|
+
|
69
|
+
Style/MethodCallWithArgsParentheses:
|
70
|
+
Enabled: true
|
71
|
+
|
72
|
+
Metrics/AbcSize:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Metrics/CyclomaticComplexity:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Metrics/PerceivedComplexity:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
Metrics/BlockLength:
|
82
|
+
Max: 30
|
83
|
+
Exclude:
|
84
|
+
- "db/**/*"
|
85
|
+
- "test/**/*"
|
86
|
+
|
87
|
+
# HttpPositionalArguments doesnt work with rails 4: https://github.com/bbatsov/rubocop/issues/3629
|
88
|
+
Rails/HttpPositionalArguments:
|
89
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
class_names (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.8.5)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 2.0)
|
17
|
+
class_names!
|
18
|
+
minitest (~> 5.0)
|
19
|
+
rake (~> 10.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# ClassNames
|
2
|
+
|
3
|
+
ClassNames is a simple helper to conditionally join class names together.
|
4
|
+
|
5
|
+
Influenced by: https://www.npmjs.com/package/classnames and https://github.com/nLight/css-class-string
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'class_names'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install class_names
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Inside of a view:
|
26
|
+
|
27
|
+
```html+erb
|
28
|
+
<!-- @conditional = false -->
|
29
|
+
<span class="<%= class_names(some: true, classy: true, [:truthy, :falsy] => @conditional) %>">
|
30
|
+
<!-- equal to -->
|
31
|
+
<span class="<%= class_names('some', 'classy', [:truthy, :falsy] => @conditional %>)">
|
32
|
+
<!-- => <span class="some classy falsy"></span> -->
|
33
|
+
```
|
34
|
+
|
35
|
+
```haml
|
36
|
+
// @conditional = true
|
37
|
+
%span{class: class_names(some: true, classy: false, [:truthy, :falsy] => @conditional)}
|
38
|
+
// equal to
|
39
|
+
%span{class: class_names('some', falsy: false, [:truthy, :falsy] => @conditional)}
|
40
|
+
// => <span class="some truthy"></span>
|
41
|
+
```
|
42
|
+
|
43
|
+
Outside of a view:
|
44
|
+
|
45
|
+
```
|
46
|
+
ClassNames::Helper.new(:str_truthy => true, :str_falsy => false}).to_s
|
47
|
+
=> "str_truthy"
|
48
|
+
|
49
|
+
ClassNames::Helper.new("truthy_1", "truthy_2").to_s
|
50
|
+
=> "truthy_1 truthy_2"
|
51
|
+
|
52
|
+
ClassNames::Helper.new({[:arr_truthy, :arr_falsy] => false}).to_s
|
53
|
+
=> "arr_falsy"
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/abodo-dev/class_names. This project is intended to be a safe, welcoming space for collaboration.
|
data/Rakefile
ADDED
data/class_names.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "class_names/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "class_names"
|
7
|
+
spec.version = ClassNames::VERSION
|
8
|
+
spec.authors = ["Harris Thompson"]
|
9
|
+
spec.email = ["hthompson@abodo.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A simple helper to conditionally join class names together.}
|
12
|
+
spec.homepage = "https://github.com/abodo-dev/class_names"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/abodo-dev/class_names"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
end
|
data/lib/class_names.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module ClassNames
|
2
|
+
class Helper
|
3
|
+
def initialize(*classes)
|
4
|
+
options = classes.last.is_a?(::Hash) ? classes.pop : {}
|
5
|
+
|
6
|
+
@classes = {}
|
7
|
+
# default to true on class_names("truthy") like calls
|
8
|
+
@classes = classes.map do |class_name|
|
9
|
+
if class_name.is_a?(::Hash)
|
10
|
+
class_name.each do |class_key, class_value|
|
11
|
+
next if !class_value
|
12
|
+
@classes[class_key] = true
|
13
|
+
end
|
14
|
+
else
|
15
|
+
{ class_name => true } if class_name
|
16
|
+
end
|
17
|
+
end.compact.reduce({}, &:merge)
|
18
|
+
@classes.merge!(options)
|
19
|
+
|
20
|
+
# handle multiple keys in hash class_names([arr_truthy, arr_falsy] => false) --> "arr_falsy"
|
21
|
+
@classes = @classes.map { |((true_css_key, false_css_key), condition)| condition ? true_css_key : false_css_key }
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
return @classes.compact.join(" ")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: class_names
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harris Thompson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- hthompson@abodo.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- class_names.gemspec
|
69
|
+
- lib/class_names.rb
|
70
|
+
- lib/class_names/helper.rb
|
71
|
+
- lib/class_names/railtie.rb
|
72
|
+
- lib/class_names/version.rb
|
73
|
+
- lib/class_names/view_helper.rb
|
74
|
+
homepage: https://github.com/abodo-dev/class_names
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
homepage_uri: https://github.com/abodo-dev/class_names
|
79
|
+
source_code_uri: https://github.com/abodo-dev/class_names
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.0.4
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A simple helper to conditionally join class names together.
|
99
|
+
test_files: []
|