clsx 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33af2843149edd1b19b3aa92deba184a299fed74da1700732f9efe88489ba95a
4
- data.tar.gz: 96747f817c0e25dafbd079923278a7a6551ba68c8ab23f509498d8993d85f4ae
3
+ metadata.gz: 16b3171bd57263e7a62fc9303c180032f9ae66a6aeb203e965ed669d1299fafa
4
+ data.tar.gz: 06f2dde23148ba2c6a1b4994404635f41b664bdeed52ef7db36fdcd81d7aa63a
5
5
  SHA512:
6
- metadata.gz: 4a81c07a59b55d498fc8e1d7b3f705da0e33aa24b319f5aadbace08f8deaa510a8724009fabe5a450f4d43d02534f084738dcb5f27855804f35a9c9a99e96450
7
- data.tar.gz: 51ddc05377658fcfd59c49daf86d69e21589666bf20ce21c7f1578fe83de7e9fcde87e2201bdab9c11c2040c1f860971f88d551886a2d628f491463f59342065
6
+ metadata.gz: 28f8655c985f735272854fd03ff64d484f06f5c0f63960ce832f9ecfed4f0ebcff0db3f3b100ffe24d8dd33b82c06e2564d0d1fe52e222c98fa62f38d5c0cbcb
7
+ data.tar.gz: 101ddbc96d910cf315ad4010a9656d4c0a0492298cd588b4e2d7bbf1782c59bdf262659d89ba967b2e33f18dac6743bff69fd5dd172ec1ce1bf20c93c7554598
data/.overcommit.yml ADDED
@@ -0,0 +1,6 @@
1
+ PreCommit:
2
+ StandardRB:
3
+ enabled: true
4
+ required: true
5
+ command: ['bundle', 'exec', 'standardrb']
6
+ flags: ['--fix']
data/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  ## [Unreleased]
2
+ ## [0.1.2] - 2024-03-02
3
+ PUBLIC RELEASE
2
4
 
3
- ## [0.1.0] - 2022-11-01
5
+ ## [0.1.1] - 2024-03-03
6
+ ### Changed
7
+ - Changed `clsx` to `CLSX`
8
+
9
+
10
+ ## [0.1.0] - 2024-03-02
4
11
 
5
12
  - Initial release
13
+
14
+ These examples should be working
15
+
16
+ Strings (variadic)
17
+ ```ruby
18
+ clsx("foo", true && "bar", "baz")
19
+ #=> "foo bar baz"
20
+ ```
21
+
22
+ Objects
23
+ ```ruby
24
+ clsx({ foo:true, bar:false, baz:is_true? })
25
+ #=> "foo baz"
26
+ ```
27
+
28
+ Objects (variadic)
29
+ ```ruby
30
+ clsx({ foo:true }, { bar:false }, null, { "--foobar":"hello" })
31
+ #=> "foo --foobar"
32
+ ```
33
+
34
+ Arrays
35
+ ```ruby
36
+ clsx(["foo", 0, false, "bar"])
37
+ #=> "foo bar"
38
+ ```
39
+
40
+ Arrays (variadic)
41
+ ```ruby
42
+ clsx(["foo"], ["", 0, false, "bar"], [["baz", [["hello"], "there"]]])
43
+ #=> "foo bar baz hello there"
44
+ ```
45
+
46
+ Kitchen sink (with nesting)
47
+ ```ruby
48
+ clsx("foo", [1 && "bar", { baz:false, bat:null }, ["hello", ["world"]]], "cya")
49
+ #=> "foo bar hello world cya"
50
+ ```
51
+
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022 Marco Roth
3
+ Copyright (c) 2024 Seth Horsley
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,18 +1,58 @@
1
- # CLSX
1
+ # Clsx
2
+ ## A gem for constructing HTML class strings conditionally
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/clsx`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ Ruby utility for constructing HTML class strings conditionally with the provided syntax, you can define a module named Clsx that includes a method to handle each case: strings, objects (hashes), arrays, and a combination of these with nested structures. This method will recursively process each argument, filter out falsy values, and concatenate the truthy values into a single string.
4
5
 
5
6
  ## Installation
6
7
 
7
8
  Install the gem and add to the application's Gemfile by executing:
8
9
 
9
- $ bundle add clsx
10
+ $ bundle add "clsx"
10
11
 
11
- If bundler is not being used to manage dependencies, install the gem by executing:
12
-
13
- $ gem install clsx
14
12
 
15
13
  ## Usage
14
+ Strings (variadic)
15
+ ```ruby
16
+ clsx("foo", true && "bar", "baz")
17
+ #=> "foo bar baz"
18
+ ```
19
+
20
+ Objects
21
+ ```ruby
22
+ clsx({ foo:true, bar:false, baz:is_true? })
23
+ #=> "foo baz"
24
+ ```
25
+
26
+ Objects (variadic)
27
+ ```ruby
28
+ clsx({ foo:true }, { bar:false }, null, { "--foobar":"hello" })
29
+ #=> "foo --foobar"
30
+ ```
31
+
32
+ Arrays
33
+ ```ruby
34
+ clsx(["foo", 0, false, "bar"])
35
+ #=> "foo bar"
36
+ ```
37
+
38
+ Arrays (variadic)
39
+ ```ruby
40
+ clsx(["foo"], ["", 0, false, "bar"], [["baz", [["hello"], "there"]]])
41
+ #=> "foo bar baz hello there"
42
+ ```
43
+
44
+ Kitchen sink (with nesting)
45
+ ```ruby
46
+ clsx("foo", [1 && "bar", { baz:false, bat:null }, ["hello", ["world"]]], "cya")
47
+ #=> "foo bar hello world cya"
48
+ ```
49
+
50
+ You can also use clsx in rails views like this:
51
+ ```ruby
52
+ <div class="<%= clsx({ 'border': true, "border-t": false, "border-b":true }) %>">
53
+ <!-- ... -->
54
+ </div>
55
+ ```
16
56
 
17
57
 
18
58
  ## Development
@@ -23,7 +63,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
23
63
 
24
64
  ## Contributing
25
65
 
26
- Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/clsx. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/marcoroth/clsx/blob/master/CODE_OF_CONDUCT.md).
66
+ Bug reports and pull requests are welcome. Just fork this repo make the changes you want and submit a pull request back to this repo :)
27
67
 
28
68
  ## License
29
69
 
@@ -31,4 +71,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
31
71
 
32
72
  ## Code of Conduct
33
73
 
34
- Everyone interacting in the Clsx project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/clsx/blob/master/CODE_OF_CONDUCT.md).
74
+ Everyone interacting in the Clsx project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/clsx/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,16 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require "rake/testtask"
4
+ require "minitest/test_task"
5
5
 
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
6
+ Minitest::TestTask.create
11
7
 
12
- require "rubocop/rake_task"
13
-
14
- RuboCop::RakeTask.new
15
-
16
- task default: %i[test rubocop]
8
+ task default: :test
@@ -0,0 +1,18 @@
1
+ require "clsx"
2
+ require "rails"
3
+
4
+ module Clsx
5
+ class Railtie < Rails::Railtie
6
+ initializer "clsx.action_view" do
7
+ ActiveSupport.on_load :action_view do
8
+ ActionView::Base.send :include, Helper
9
+ end
10
+ end
11
+ end
12
+
13
+ module Helper
14
+ def clsx(*)
15
+ CLSX.clsx(*)
16
+ end
17
+ end
18
+ end
data/lib/clsx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLSX
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/clsx.rb CHANGED
@@ -1,6 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "clsx/version"
4
+ require "clsx/railtie" if defined?(Rails)
4
5
 
5
6
  module CLSX
7
+ class Error < StandardError; end
8
+
9
+ def self.clsx(*args)
10
+ args.flat_map { |arg| parse(arg) }.compact.join(" ")
11
+ end
12
+
13
+ def self.parse(arg)
14
+ case arg
15
+ when String
16
+ arg unless arg.empty?
17
+ when Hash
18
+ arg.map { |k, v| k if v }.compact
19
+ when Array
20
+ arg.flat_map { |a| parse(a) }
21
+ end
22
+ end
6
23
  end
data/sig/clsx.rbs CHANGED
@@ -1,3 +1,4 @@
1
1
  module CLSX
2
2
  VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
4
  end
metadata CHANGED
@@ -1,41 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Marco Roth
7
+ - Seth Horsley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-01 00:00:00.000000000 Z
11
+ date: 2024-03-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A tiny utility for constructing CSS class strings conditionally.
13
+ description: 'Ruby utility for constructing HTML class strings conditionally with
14
+ the provided syntax, you can define a module named Clsx that includes a method to
15
+ handle each case: strings, objects (hashes), arrays, and a combination of these
16
+ with nested structures. This method will recursively process each argument, filter
17
+ out falsy values, and concatenate the truthy values into a single string.'
14
18
  email:
15
- - marco.roth@hey.com
19
+ - isethi@me.com
16
20
  executables: []
17
21
  extensions: []
18
22
  extra_rdoc_files: []
19
23
  files:
20
- - ".rubocop.yml"
24
+ - ".overcommit.yml"
21
25
  - CHANGELOG.md
22
- - CODE_OF_CONDUCT.md
23
- - Gemfile
24
- - Gemfile.lock
25
26
  - LICENSE.txt
26
27
  - README.md
27
28
  - Rakefile
28
29
  - lib/clsx.rb
30
+ - lib/clsx/railtie.rb
29
31
  - lib/clsx/version.rb
30
32
  - sig/clsx.rbs
31
- homepage: https://github.com/marcoroth/clsx
33
+ homepage: https://github.com/iseth/ruby-clsx
32
34
  licenses:
33
35
  - MIT
34
36
  metadata:
35
- homepage_uri: https://github.com/marcoroth/clsx
36
- source_code_uri: https://github.com/marcoroth/clsx
37
- changelog_uri: https://github.com/marcoroth/clsx/blob/main/CHANGELOG.md
38
- rubygems_mfa_required: 'true'
37
+ homepage_uri: https://github.com/iseth/ruby-clsx
38
+ source_code_uri: https://github.com/iseth/ruby-clsx
39
+ changelog_uri: https://github.com/iseth/ruby-clsx/blob/main/CHANGELOG.md
39
40
  post_install_message:
40
41
  rdoc_options: []
41
42
  require_paths:
@@ -44,15 +45,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - ">="
46
47
  - !ruby/object:Gem::Version
47
- version: 2.7.0
48
+ version: 2.6.0
48
49
  required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  requirements:
50
51
  - - ">="
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  requirements: []
54
- rubygems_version: 3.3.7
55
+ rubygems_version: 3.5.6
55
56
  signing_key:
56
57
  specification_version: 4
57
- summary: A tiny utility for constructing CSS class strings conditionally.
58
+ summary: A gem for constructing HTML class strings conditionally
58
59
  test_files: []
data/.rubocop.yml DELETED
@@ -1,18 +0,0 @@
1
- AllCops:
2
- NewCops: enable
3
- TargetRubyVersion: 2.7
4
- SuggestExtensions: false
5
-
6
- Style/StringLiterals:
7
- Enabled: true
8
- EnforcedStyle: double_quotes
9
-
10
- Style/StringLiteralsInInterpolation:
11
- Enabled: true
12
- EnforcedStyle: double_quotes
13
-
14
- Style/Documentation:
15
- Enabled: false
16
-
17
- Layout/LineLength:
18
- Max: 120
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at marco.roth@intergga.ch. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec
6
-
7
- gem "minitest", "~> 5.0"
8
- gem "rake", "~> 13.0"
9
- gem "rubocop", "~> 1.21"
data/Gemfile.lock DELETED
@@ -1,45 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- clsx (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.2)
10
- json (2.6.2)
11
- minitest (5.16.3)
12
- parallel (1.22.1)
13
- parser (3.1.2.1)
14
- ast (~> 2.4.1)
15
- rainbow (3.1.1)
16
- rake (13.0.6)
17
- regexp_parser (2.6.0)
18
- rexml (3.2.5)
19
- rubocop (1.37.1)
20
- json (~> 2.3)
21
- parallel (~> 1.10)
22
- parser (>= 3.1.2.1)
23
- rainbow (>= 2.2.2, < 4.0)
24
- regexp_parser (>= 1.8, < 3.0)
25
- rexml (>= 3.2.5, < 4.0)
26
- rubocop-ast (>= 1.23.0, < 2.0)
27
- ruby-progressbar (~> 1.7)
28
- unicode-display_width (>= 1.4.0, < 3.0)
29
- rubocop-ast (1.23.0)
30
- parser (>= 3.1.1.0)
31
- ruby-progressbar (1.11.0)
32
- unicode-display_width (2.3.0)
33
-
34
- PLATFORMS
35
- x86_64-darwin-19
36
- x86_64-linux
37
-
38
- DEPENDENCIES
39
- clsx!
40
- minitest (~> 5.0)
41
- rake (~> 13.0)
42
- rubocop (~> 1.21)
43
-
44
- BUNDLED WITH
45
- 2.3.22