File tree Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change
1
+ ## Unreleased
2
+ - Fix issue with inherited hook in helper ([ #33 ] ( https://github.com/avo-hq/class_variants/pull/33 ) )
3
+
1
4
## 1.1.0 (2025-01-20)
2
5
- Add support for merging ([ #23 ] ( https://github.com/avo-hq/class_variants/pull/23 ) )
3
6
- Add support for subclass inheritance in helper ([ #24 ] ( https://github.com/avo-hq/class_variants/pull/24 ) )
Original file line number Diff line number Diff line change @@ -11,9 +11,12 @@ def class_variants(...)
11
11
def self . included ( base )
12
12
base . extend ( ClassMethods )
13
13
base . singleton_class . instance_variable_set ( :@_class_variants_instance , ClassVariants ::Instance . new )
14
- base . define_singleton_method ( :inherited ) do |subclass |
14
+
15
+ def base . inherited ( subclass )
16
+ super if defined? ( super )
17
+
15
18
subclass . singleton_class . instance_variable_set (
16
- :@_class_variants_instance , base . singleton_class . instance_variable_get ( :@_class_variants_instance ) . dup
19
+ :@_class_variants_instance , singleton_class . instance_variable_get ( :@_class_variants_instance ) . dup
17
20
)
18
21
end
19
22
end
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ button_classes = ClassVariants.build(
98
98
)
99
99
100
100
button_classes.render(color: :red ) # => "inline-flex items-center rounded bg-red-600"
101
- button_classes.render(color: :red , border: true ) # => "inline-flex items-center rounded bg-red-600 border border-red-600 "
101
+ button_classes.render(color: :red , border: true ) # => "inline-flex items-center rounded bg-red-600 border border-red-800 "
102
102
```
103
103
104
104
## Override classes with ` render `
@@ -362,8 +362,9 @@ Install the gem using `bundle add tailwind_merge` and use this configuration to
362
362
363
363
``` ruby
364
364
ClassVariants .configure do |config |
365
+ merger = TailwindMerge ::Merger .new
365
366
config.process_classes_with do |classes |
366
- TailwindMerge :: Merger . new .merge(classes)
367
+ merger .merge(classes)
367
368
end
368
369
end
369
370
```
Original file line number Diff line number Diff line change 1
1
require "test_helper"
2
2
3
3
class HelperTest < Minitest ::Test
4
- class DemoClass
4
+ class BaseClass
5
+ end
6
+
7
+ class DemoClass < BaseClass
5
8
include ClassVariants ::Helper
6
9
7
10
class_variants base : "rounded border"
8
11
end
9
12
10
- class Subclass < DemoClass
13
+ class SubClass < DemoClass
11
14
class_variants base : "bg-black"
12
15
end
13
16
17
+ def test_inherited
18
+ mock = Minitest ::Mock . new
19
+ mock . expect ( :call , nil , [ Class ] )
20
+
21
+ BaseClass . stub ( :inherited , mock ) do
22
+ Class . new ( DemoClass )
23
+ end
24
+
25
+ mock . verify
26
+ end
27
+
14
28
def test_call_from_instance
15
29
assert_equal "rounded border" , DemoClass . new . class_variants
16
30
end
17
31
18
32
def test_call_from_subclass
19
- assert_equal "rounded border bg-black" , Subclass . new . class_variants
33
+ assert_equal "rounded border bg-black" , SubClass . new . class_variants
20
34
end
21
35
end
You can’t perform that action at this time.
0 commit comments