class_variants 0.0.5 → 0.0.7
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/lib/class_variants/instance.rb +35 -21
- data/lib/class_variants/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765533378fe25d4d376f7b79d3071f056438f7c94ddddcdd45043d54669c1859
|
4
|
+
data.tar.gz: d05e57bd9f860e806687b52ee20faeffb59b2774904ec6fb84f3403bdff7d692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7517aed893faec0040d34907290f335135631fd12268359687dbcf411b4cbe1cc206ed9a1bffd34ad667bd3e43166300efa9fae7f81ae44c5bf129d6587805e
|
7
|
+
data.tar.gz: c1bb443cc535bd4eec83ebcc6880a851ab8c3bd89342406f904c83136006a082f60092111a20d05273b014639342ca8fb3faa9e67cb6a326e351411e18e57522
|
@@ -3,37 +3,51 @@ class ClassVariants::Instance
|
|
3
3
|
attr_reader :variants
|
4
4
|
attr_reader :defaults
|
5
5
|
|
6
|
-
def initialize(classes = "", variants: {}, defaults: {})
|
6
|
+
def initialize(classes = "", variants: {}, compoundVariants: [], defaults: {})
|
7
7
|
@classes = classes
|
8
|
-
@variants = variants
|
8
|
+
@variants = expand_boolean_variants(variants)
|
9
|
+
@compoundVariants = compoundVariants
|
9
10
|
@defaults = defaults
|
10
11
|
end
|
11
12
|
|
12
|
-
def render(**
|
13
|
-
|
13
|
+
def render(**overrides)
|
14
|
+
# Start with our default classes
|
15
|
+
result = [@classes]
|
14
16
|
|
15
|
-
#
|
16
|
-
|
17
|
+
# Then merge the passed in overrides on top of the defaults
|
18
|
+
selected = @defaults.merge(overrides)
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Go through each keys provided
|
22
|
-
settings.each do |key, value|
|
23
|
-
if variants.keys.include? key
|
24
|
-
applied_options << key
|
25
|
-
result << variants[key][value]
|
26
|
-
end
|
20
|
+
selected.each do |variant_type, variant|
|
21
|
+
# dig the classes out and add them to the result
|
22
|
+
result << @variants.dig(variant_type, variant)
|
27
23
|
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
result << @variants[key][key_to_use] if @variants[key].present?
|
33
|
-
end
|
25
|
+
@compoundVariants.each do |compound_variant|
|
26
|
+
if (compound_variant.keys - [:class]).all? { |key| selected[key] == compound_variant[key] }
|
27
|
+
result << compound_variant[:class]
|
34
28
|
end
|
35
29
|
end
|
36
30
|
|
31
|
+
# Compact out any nil values we may have dug up
|
32
|
+
result.compact!
|
33
|
+
|
34
|
+
# Return the final token list
|
37
35
|
result.join " "
|
38
36
|
end
|
39
|
-
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def expand_boolean_variants(variants)
|
41
|
+
variants.each.map { |key, value|
|
42
|
+
case value
|
43
|
+
when String
|
44
|
+
s_key = key.to_s
|
45
|
+
{ s_key.delete_prefix("!").to_sym => { !s_key.start_with?("!") => value } }
|
46
|
+
else
|
47
|
+
{ key => value }
|
48
|
+
end
|
49
|
+
}.reduce do |variants, more_variants|
|
50
|
+
variants.merge!(more_variants) { |_key, v1, v2| v1.merge!(v2) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_variants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2023-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: benchmark-ips
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Easily configure styles and apply them as classes.
|
14
28
|
email: adrian@adrianthedev.com
|
15
29
|
executables: []
|
@@ -43,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
57
|
- !ruby/object:Gem::Version
|
44
58
|
version: '0'
|
45
59
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.4.6
|
47
61
|
signing_key:
|
48
62
|
specification_version: 4
|
49
63
|
summary: Easily configure styles and apply them as classes.
|