clsx-rails 1.0.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +33 -3
- data/README.md +26 -6
- data/lib/clsx/helper.rb +12 -8
- data/lib/clsx/version.rb +1 -1
- data/lib/clsx-rails.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458496856224ba13decce2fcc1c4a15efd2eb8a44f86639c7eba9ecd5a06027a
|
4
|
+
data.tar.gz: 10dffbb660e3888a3d1379642d9895cc2cb63acde24e15cce06ae00428517722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72edd36ee323a3a8900d949142676f0539e44e1daa965fd2a02c87d7e8ec182bb2caa69f7494468d3bc500e8ad600d320839e70e4d0f3fac41589e3a541981ff
|
7
|
+
data.tar.gz: b65cf587a989e8ceac0b2b71c1e6ef518e2bd0761143fba3db407e9598d7c3e69de58fe92445e69eb70deb6df77e57c1e25c1f8c61c5601bbedeab4ab417657d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
|
6
|
+
|
7
|
+
## Unreleased changes
|
8
|
+
|
9
|
+
## v1.0.1 (2024-03-04)
|
10
|
+
|
11
|
+
### Performance Improvements
|
12
|
+
- Speeds up the performance by 2x [`32236ed`](git@github.com:svyatov/clsx-rails/commit/32236ed)
|
13
|
+
|
14
|
+
### Chore
|
15
|
+
- Fixes CI action [`f1b948c`](git@github.com:svyatov/clsx-rails/commit/f1b948c)
|
16
|
+
- Upload code coverage to CodeCov for the latest combination of Ruby and ActionView only [`4e5d768`](git@github.com:svyatov/clsx-rails/commit/4e5d768)
|
17
|
+
|
18
|
+
### Documentation
|
19
|
+
- Adds information about supported Ruby and Rails version [skip ci] [`2e6483f`](git@github.com:svyatov/clsx-rails/commit/2e6483f)
|
20
|
+
- Adds link to the CodeCov badge, switch to Conventional Commits [`b48cc84`](git@github.com:svyatov/clsx-rails/commit/b48cc84)
|
21
|
+
|
22
|
+
### Other
|
23
|
+
- Updates CI badge [skip ci] [`a829613`](git@github.com:svyatov/clsx-rails/commit/a829613)
|
24
|
+
- Adds code coverage tracking [`0c5d34c`](git@github.com:svyatov/clsx-rails/commit/0c5d34c)
|
25
|
+
- Ignore ruby-head in the CI matrix [`f3ab4df`](git@github.com:svyatov/clsx-rails/commit/f3ab4df)
|
26
|
+
- Better name for the GitHub Action job [`a28adb7`](git@github.com:svyatov/clsx-rails/commit/a28adb7)
|
27
|
+
- Adds badges, fixes rubocop configuration for CI [`56fab44`](git@github.com:svyatov/clsx-rails/commit/56fab44)
|
28
|
+
- Create dependabot.yml [`ed1e0eb`](git@github.com:svyatov/clsx-rails/commit/ed1e0eb)
|
29
|
+
- Fixes GitHub Actions [`f58a4b2`](git@github.com:svyatov/clsx-rails/commit/f58a4b2)
|
30
|
+
|
31
|
+
## v1.0.0 (2024-03-03)
|
32
|
+
|
33
|
+
### Other
|
34
|
+
- Initial commit [`f65b9b8`](git@github.com:svyatov/clsx-rails/commit/f65b9b8)
|
4
35
|
|
5
|
-
- Initial release
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# clsx-rails
|
1
|
+
# clsx-rails [](https://rubygems.org/gems/clsx-rails) [](https://app.codecov.io/gh/svyatov/clsx-rails) [](https://github.com/svyatov/clsx-rails/actions?query=workflow%3ACI) [](LICENSE.txt)
|
2
2
|
|
3
3
|
> A tiny Rails view helper for constructing CSS class strings conditionally.
|
4
4
|
|
@@ -6,21 +6,29 @@ This gem is essentially a clone if the [clsx](https://github.com/lukeed/clsx) np
|
|
6
6
|
It provides a simple way to conditionally apply classes to HTML elements in Rails views.
|
7
7
|
It is especially useful when you have a lot of conditional classes and you want to keep your views clean and readable.
|
8
8
|
|
9
|
+
## Supported Ruby and Rails versions
|
10
|
+
|
11
|
+
Ruby 3.1+ and Rails 7.0+ are supported.
|
12
|
+
|
9
13
|
## Installation
|
10
14
|
|
11
15
|
Install the gem and add to the application's Gemfile by executing:
|
12
16
|
|
13
|
-
|
17
|
+
```bash
|
18
|
+
bundle add clsx-rails
|
19
|
+
```
|
14
20
|
|
15
|
-
|
21
|
+
Or add it manually to the Gemfile:
|
16
22
|
|
17
|
-
|
23
|
+
```ruby
|
24
|
+
gem 'clsx-rails', '~> 1.0'
|
25
|
+
```
|
18
26
|
|
19
27
|
## Usage
|
20
28
|
|
21
|
-
The `clsx` method can be used in views to conditionally apply classes to HTML elements.
|
29
|
+
The `clsx` helper method can be used in views to conditionally apply classes to HTML elements.
|
22
30
|
You can also use a slightly more conise `cn` alias.
|
23
|
-
It accepts a variety of arguments and returns a string of classes.
|
31
|
+
It accepts a variety of arguments and returns a string of unique classes.
|
24
32
|
|
25
33
|
```ruby
|
26
34
|
# Strings (variadic)
|
@@ -151,6 +159,18 @@ There is a simple benchmark script in the `benchmark` directory.
|
|
151
159
|
You can run it with `bundle exec ruby benchmark/run.rb`.
|
152
160
|
I've added it for easier performance testing when making changes to the gem.
|
153
161
|
|
162
|
+
## Conventional Commits
|
163
|
+
|
164
|
+
This project uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages.
|
165
|
+
|
166
|
+
Types of commits are:
|
167
|
+
- `feat`: a new feature
|
168
|
+
- `fix`: a bug fix
|
169
|
+
- `perf`: code that improves performance
|
170
|
+
- `chore`: updating build tasks, configs, formatting etc; no code change
|
171
|
+
- `docs`: changes to documentation
|
172
|
+
- `refactor`: refactoring code
|
173
|
+
|
154
174
|
## Contributing
|
155
175
|
|
156
176
|
Bug reports and pull requests are welcome on GitHub at https://github.com/svyatov/clsx-rails.
|
data/lib/clsx/helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'set'
|
4
|
-
require 'action_view'
|
5
4
|
|
6
5
|
# :nodoc:
|
7
6
|
module Clsx
|
@@ -27,7 +26,9 @@ module Clsx
|
|
27
26
|
# <div class="<%= clsx('foo', active: @is_active, 'another-class' => @condition) %>">
|
28
27
|
# <%= tag.div class: clsx(%w[foo bar], hidden: @condition) do ... end %>
|
29
28
|
def clsx(*args)
|
30
|
-
clsx_args_processor(*args)
|
29
|
+
result = clsx_args_processor(*args)
|
30
|
+
result.uniq!
|
31
|
+
result.join(' ').presence
|
31
32
|
end
|
32
33
|
alias cn clsx
|
33
34
|
|
@@ -35,19 +36,22 @@ module Clsx
|
|
35
36
|
|
36
37
|
# @param [Mixed] args
|
37
38
|
#
|
38
|
-
# @return [
|
39
|
-
def clsx_args_processor(*args) # rubocop:disable Metrics/CyclomaticComplexity
|
40
|
-
result =
|
41
|
-
|
39
|
+
# @return [Array]
|
40
|
+
def clsx_args_processor(*args) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
41
|
+
result = []
|
42
|
+
complex_keys = []
|
42
43
|
|
44
|
+
args.flatten!
|
43
45
|
args.each do |arg|
|
44
46
|
next if arg.blank? || arg.is_a?(TrueClass) || arg.is_a?(Proc)
|
45
47
|
next result << arg.to_s unless arg.is_a?(Hash)
|
46
48
|
|
47
|
-
arg.each { |
|
49
|
+
arg.each { |key, value| complex_keys << key if value }
|
48
50
|
end
|
49
51
|
|
50
|
-
result
|
52
|
+
return result if complex_keys.empty?
|
53
|
+
|
54
|
+
result + clsx_args_processor(*complex_keys)
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
data/lib/clsx/version.rb
CHANGED
data/lib/clsx-rails.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clsx-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonid Svyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|