-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for post process classes
- Loading branch information
Showing
8 changed files
with
91 additions
and
1 deletion.
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 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
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,11 @@ | ||
module ClassVariants | ||
class Configuration | ||
def process_classes_with(&block) | ||
if block_given? | ||
@process_classes_with = block | ||
else | ||
@process_classes_with | ||
end | ||
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
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,19 @@ | ||
require "test_helper" | ||
|
||
class ConfigurationTest < Minitest::Test | ||
def teardown | ||
ClassVariants.configuration.instance_variable_set(:@process_classes_with, nil) | ||
end | ||
|
||
def test_configuration_process_classes_with_default | ||
refute ClassVariants.configuration.process_classes_with | ||
end | ||
|
||
def test_configure | ||
ClassVariants.configure do |config| | ||
config.process_classes_with { |classes| classes } | ||
end | ||
|
||
assert_respond_to ClassVariants.configuration.process_classes_with, :call | ||
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,34 @@ | ||
require "test_helper" | ||
|
||
class ProcessClassesWithTest < Minitest::Test | ||
def teardown | ||
ClassVariants.configuration.instance_variable_set(:@process_classes_with, nil) | ||
end | ||
|
||
def test_without_classes_processor | ||
assert_equal "border rounded px-2 py-1 p-5", ClassVariants.build(base: "border rounded px-2 py-1 p-5").render | ||
end | ||
|
||
def test_with_classes_processor | ||
ClassVariants.configure do |config| | ||
config.process_classes_with do |classes| | ||
merger.merge(classes) | ||
end | ||
end | ||
|
||
assert_equal "border rounded p-5", ClassVariants.build(base: "border rounded px-2 py-1 p-5").render | ||
end | ||
|
||
private | ||
|
||
def merger | ||
require "tailwind_merge" | ||
TailwindMerge::Merger.new | ||
rescue LoadError | ||
Class.new do | ||
def merge(classes) | ||
classes.gsub("px-2 py-1 ", "") | ||
end | ||
end.new | ||
end | ||
end |