-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
614c8a6
commit 170e66c
Showing
8 changed files
with
171 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
clsx (0.1.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
minitest (5.22.2) | ||
rake (13.1.0) | ||
|
||
PLATFORMS | ||
arm64-darwin-23 | ||
ruby | ||
|
||
DEPENDENCIES | ||
clsx! | ||
minitest (~> 5.16) | ||
rake (~> 13.0) | ||
|
||
BUNDLED WITH | ||
2.5.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "clsx/version" | ||
require "clsx/railtie" if defined?(Rails) | ||
|
||
module Clsx | ||
class Error < StandardError; end | ||
# Your code goes here... | ||
|
||
def self.clsx(*args) | ||
args.flat_map { |arg| parse(arg) }.compact.join(" ") | ||
end | ||
|
||
private | ||
|
||
def self.parse(arg) | ||
case arg | ||
when String | ||
arg unless arg.empty? | ||
when Hash | ||
arg.map { |k, v| k if v }.compact | ||
when Array | ||
arg.flat_map { |a| parse(a) } | ||
else | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "clsx" | ||
require "rails" | ||
|
||
module Clsx | ||
class Railtie < Rails::Railtie | ||
initializer "clsx.action_view" do | ||
ActiveSupport.on_load :action_view do | ||
ActionView::Base.send :include, Helper | ||
end | ||
end | ||
end | ||
|
||
module Helper | ||
def clsx(*args) | ||
Clsx.clsx(*args) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters