class_names 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 7252ad0407a66b839b7b9b81c5477780bdb3e9a57646c2bd055664cc5ba4f446
4
- data.tar.gz: 59e5438cfc0fbed29c787cdaad64c1dbd5092ddd6115165125966a1321bbe8ca
3
+ metadata.gz: b65124636f3d94f9009bfb7709fcc85adcecb2c2ca0e976c214006e2be5d7e02
4
+ data.tar.gz: a10164f19bd4cea67ce6b8295cc177836f6f7d23c8fdfb409eac02f611b9c473
5
5
  SHA512:
6
- metadata.gz: bc6d44a8725469c947a5888c29dd908d06073b7911e81de1ace8b9d04cc7e28445fb567b0c0d52e972280a9c76962f86509810563dac82114a4152a2cf199971
7
- data.tar.gz: 366c3e7ac44d147ccd1080460b67eb06c9124b1bb6e5f7f4ead6b9336f56b62e7046b1df2529a9d34d0dffa26654f2002a8ca5bc8ce29276eede062c6dc6e032
6
+ metadata.gz: 780ca3e59e40c200554914de8d580d66cb70c32819a00427053f9132cd772ca59c8b7aa62127607109f9868b704688863d50c1f541ba00688a7e2654b2a2acf3
7
+ data.tar.gz: f00dba300d98fec3fc6abc3a7e2caad22bba5c2771397c63210e7e0fd08630b0643f320618a5a00b561086690e1f7e17020c5c5cd395c25100a18ebdd52a02b9
@@ -0,0 +1,44 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ name: Build + Publish
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@master
18
+ - name: Set up Ruby 2.6
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: 2.6.x
22
+
23
+ - name: Publish to GPR
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
33
+ OWNER: abodo-dev
34
+
35
+ - name: Publish to RubyGems
36
+ run: |
37
+ mkdir -p $HOME/.gem
38
+ touch $HOME/.gem/credentials
39
+ chmod 0600 $HOME/.gem/credentials
40
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
+ gem build *.gemspec
42
+ gem push *.gem
43
+ env:
44
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
@@ -5,9 +5,6 @@ require:
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.3
7
7
  TargetRailsVersion: 4.2
8
- Exclude:
9
- - db/schema.rb
10
- - 'vendor/**/*'
11
8
 
12
9
  Metrics/LineLength:
13
10
  Max: 125
@@ -50,8 +47,6 @@ Style/SymbolArray:
50
47
 
51
48
  Metrics/MethodLength:
52
49
  Max: 30
53
- Exclude:
54
- - "db/**/*"
55
50
 
56
51
  ClassLength:
57
52
  Max: 500
@@ -80,10 +75,4 @@ Metrics/PerceivedComplexity:
80
75
 
81
76
  Metrics/BlockLength:
82
77
  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
78
+ - "test/**/*"
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- class_names (0.1.0)
4
+ class_names (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- minitest (5.8.5)
10
- rake (10.5.0)
9
+ minitest (5.14.0)
10
+ rake (13.0.1)
11
11
 
12
12
  PLATFORMS
13
13
  ruby
@@ -15,8 +15,8 @@ PLATFORMS
15
15
  DEPENDENCIES
16
16
  bundler (~> 2.0)
17
17
  class_names!
18
- minitest (~> 5.0)
19
- rake (~> 10.0)
18
+ minitest
19
+ rake
20
20
 
21
21
  BUNDLED WITH
22
- 2.0.2
22
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Harris Joseph Thompson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ClassNames
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/class_names.svg)](https://badge.fury.io/rb/class_names)
4
+
3
5
  ClassNames is a simple helper to conditionally join class names together.
4
6
 
5
7
  Influenced by: https://www.npmjs.com/package/classnames and https://github.com/nLight/css-class-string
@@ -25,18 +27,42 @@ Or install it yourself as:
25
27
  Inside of a view:
26
28
 
27
29
  ```html+erb
28
- <!-- @conditional = false -->
29
- <span class="<%= class_names(some: true, classy: true, [:truthy, :falsy] => @conditional) %>">
30
+ <span class="<%= class_names('foo', 'bar') %>">
31
+ <!-- => <span class="foo bar"></span> -->
32
+
33
+ <span class="<%= class_names('foo', { bar: true }) %>">
34
+ <!-- => <span class="foo bar"></span> -->
35
+
36
+ <span class="<%= class_names('foo-bar': true) %>">
37
+ <!-- => <span class="foo-bar"></span> -->
38
+
39
+ <span class="<%= class_names('foo-bar': false) %>">
40
+ <!-- => <span class=""></span> -->
41
+
42
+ <span class="<%= class_names(foo: true, bar: true) %>">
43
+ <!-- => <span class="foo bar"></span> -->
44
+
45
+ <span class="<%= class_names({ foo: true, bar: true }) %>">
46
+ <!-- => <span class="foo bar"></span> -->
47
+
48
+ <!-- Simple ternary replacement with multiple hashes -->
49
+ <span class="<%= class_names([:truthy, :falsy] => true) %>">
50
+ <!-- => <span class="truthy"></span> -->
51
+
52
+ <span class="<%= class_names([:truthy, :falsy] => false) %>">
53
+ <!-- => <span class="falsy"></span> -->
54
+
55
+ <!-- Lots of different types of arguments -->
56
+ <span class="<%= class_names(some: true, classy: true, [:truthy, :falsy] => false, 'foo') %>">
30
57
  <!-- equal to -->
31
- <span class="<%= class_names('some', 'classy', [:truthy, :falsy] => @conditional %>)">
32
- <!-- => <span class="some classy falsy"></span> -->
58
+ <span class="<%= class_names('some', 'classy', [:truthy, :falsy] => false %>, 'foo')">
59
+ <!-- => <span class="some classy falsy foo"></span> -->
33
60
  ```
34
61
 
35
62
  ```haml
36
- // @conditional = true
37
- %span{class: class_names(some: true, classy: false, [:truthy, :falsy] => @conditional)}
63
+ %span{class: class_names(some: true, classy: false, [:truthy, :falsy] => true)}
38
64
  // equal to
39
- %span{class: class_names('some', falsy: false, [:truthy, :falsy] => @conditional)}
65
+ %span{class: class_names('some', falsy: false, [:truthy, :falsy] => true)}
40
66
  // => <span class="some truthy"></span>
41
67
  ```
42
68
 
@@ -62,3 +88,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
62
88
  ## Contributing
63
89
 
64
90
  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.
91
+
92
+ ## Performance
93
+ On 50,000 calls. The unit of time is seconds.
94
+
95
+ | | user | system | total | real |
96
+ |----------------------------------|----------|----------|----------|-------------|
97
+ | With 1 array and 1 string value | 0.660000 | 0.000000 | 0.660000 | (0.657901) |
98
+ | With 5 array and 5 string values | 0.640000 | 0.000000 | 0.640000 | (0.650673) |
99
+ | With 10 array values | 0.450000 | 0.000000 | 0.450000 | (0.449735) |
100
+ | With 10 string values | 0.320000 | 0.010000 | 0.330000 | (0.320911) |
@@ -8,7 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Harris Thompson"]
9
9
  spec.email = ["hthompson@abodo.com"]
10
10
 
11
- spec.summary = %q{A simple helper to conditionally join class names together.}
11
+ spec.summary = %q{A simple helper to conditionally join class names together}
12
+ spec.description = %q{The class_names function takes any number of arguments which can be a string or hash. The argument 'foo' is short for { foo: true }. If the value associated with a given key is falsy (nil or false), that key won't be included in the output.}
12
13
  spec.homepage = "https://github.com/abodo-dev/class_names"
13
14
  spec.license = "MIT"
14
15
 
@@ -25,6 +26,6 @@ Gem::Specification.new do |spec|
25
26
  spec.require_paths = ["lib"]
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 2.0"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "minitest"
30
31
  end
@@ -1,11 +1,11 @@
1
1
  module ClassNames
2
2
  class Helper
3
- def initialize(*classes)
4
- options = classes.last.is_a?(::Hash) ? classes.pop : {}
3
+ def initialize(*class_map)
4
+ options = class_map.last.is_a?(::Hash) ? class_map.pop : {}
5
5
 
6
6
  @classes = {}
7
7
  # default to true on class_names("truthy") like calls
8
- @classes = classes.map do |class_name|
8
+ @classes = class_map.map do |class_name|
9
9
  if class_name.is_a?(::Hash)
10
10
  class_name.each do |class_key, class_value|
11
11
  next if !class_value
@@ -25,4 +25,4 @@ module ClassNames
25
25
  return @classes.compact.join(" ")
26
26
  end
27
27
  end
28
- end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module ClassNames
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,43 @@
1
+ require("benchmark")
2
+ require("securerandom")
3
+ require("class_names/view_helper")
4
+ include ClassNames::ViewHelper
5
+
6
+ NUMBER_OF_CALLS = 50_000
7
+
8
+ def class_name
9
+ SecureRandom.hex(4)
10
+ end
11
+
12
+ def true_or_false
13
+ [true, false].sample
14
+ end
15
+
16
+ arrays = Enumerator.new { |y| y << [[class_name, class_name], true_or_false] }
17
+ strings = Enumerator.new { |y| y << [class_name, true_or_false] }
18
+
19
+ Benchmark.bm do |b|
20
+ b.report("With 1 array and 1 string value") do
21
+ NUMBER_OF_CALLS.times do
22
+ class_names(Hash[arrays.take(1) + strings.take(1)])
23
+ end
24
+ end
25
+
26
+ b.report("With 5 array and 5 string values") do
27
+ NUMBER_OF_CALLS.times do
28
+ class_names(Hash[arrays.take(5) + strings.take(5)])
29
+ end
30
+ end
31
+
32
+ b.report("With 10 array values") do
33
+ NUMBER_OF_CALLS.times do
34
+ class_names(Hash[arrays.take(10)])
35
+ end
36
+ end
37
+
38
+ b.report("With 10 string values") do
39
+ NUMBER_OF_CALLS.times do
40
+ class_names(Hash[strings.take(10)])
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: class_names
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harris Thompson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-06 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,41 +28,46 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
55
- description:
54
+ version: '0'
55
+ description: 'The class_names function takes any number of arguments which can be
56
+ a string or hash. The argument ''foo'' is short for { foo: true }. If the value
57
+ associated with a given key is falsy (nil or false), that key won''t be included
58
+ in the output.'
56
59
  email:
57
60
  - hthompson@abodo.com
58
61
  executables: []
59
62
  extensions: []
60
63
  extra_rdoc_files: []
61
64
  files:
65
+ - ".github/workflows/gempush.yml"
62
66
  - ".gitignore"
63
67
  - ".rubocop.yml"
64
68
  - Gemfile
65
69
  - Gemfile.lock
70
+ - LICENSE
66
71
  - README.md
67
72
  - Rakefile
68
73
  - class_names.gemspec
@@ -71,6 +76,7 @@ files:
71
76
  - lib/class_names/railtie.rb
72
77
  - lib/class_names/version.rb
73
78
  - lib/class_names/view_helper.rb
79
+ - profiling/benchmark.rb
74
80
  homepage: https://github.com/abodo-dev/class_names
75
81
  licenses:
76
82
  - MIT
@@ -92,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
98
  - !ruby/object:Gem::Version
93
99
  version: '0'
94
100
  requirements: []
95
- rubygems_version: 3.0.4
101
+ rubygems_version: 3.0.6
96
102
  signing_key:
97
103
  specification_version: 4
98
- summary: A simple helper to conditionally join class names together.
104
+ summary: A simple helper to conditionally join class names together
99
105
  test_files: []