class_variants 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/class_variants/instance.rb +28 -22
- data/lib/class_variants/version.rb +1 -1
- data/lib/class_variants.rb +5 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2012fb19a3b94a62a3278f1256167126ef85e203a967cc20f8cb67d6fc94bfcb
|
4
|
+
data.tar.gz: ec7bf120843ba12c34f7bfbef26f5170fac8bd4e7f40d7717c6a478bf0116cbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fceccde2ac9e59dad730915436bd9d8fc2193316c8ce494e76227ac6f64de4bbffa448adc06f70f811a3c869c4b767d489ad750aff41e942ecc4afdc3545b4cd
|
7
|
+
data.tar.gz: b881d68c49c2e9cccea155e021aafcaad68ec2df3d48c9c78afac833b96e8c0cc325c174bf34660733ed64570501477351f8b8bf5672290fdd1ed10cf1ab41f3
|
@@ -5,35 +5,41 @@ class ClassVariants::Instance
|
|
5
5
|
|
6
6
|
def initialize(classes = "", variants: {}, defaults: {})
|
7
7
|
@classes = classes
|
8
|
-
@variants = variants
|
8
|
+
@variants = expand_boolean_variants(variants)
|
9
9
|
@defaults = defaults
|
10
10
|
end
|
11
11
|
|
12
|
-
def render(**
|
13
|
-
|
12
|
+
def render(**overrides)
|
13
|
+
# Start with our default classes
|
14
|
+
result = [@classes]
|
14
15
|
|
15
|
-
#
|
16
|
-
|
16
|
+
# Then merge the passed in overrides on top of the defaults
|
17
|
+
@defaults.merge(overrides)
|
18
|
+
.each do |variant_type, variant|
|
19
|
+
# dig the classes out and add them to the result
|
20
|
+
result << @variants.dig(variant_type, variant)
|
21
|
+
end
|
17
22
|
|
18
|
-
#
|
19
|
-
|
23
|
+
# Compact out any nil values we may have dug up
|
24
|
+
result.compact!
|
20
25
|
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
26
|
+
# Return the final token list
|
27
|
+
result.join " "
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def expand_boolean_variants(variants)
|
33
|
+
variants.each.map { |key, value|
|
34
|
+
case value
|
35
|
+
when String
|
36
|
+
s_key = key.to_s
|
37
|
+
{ s_key.delete_prefix("!").to_sym => { !s_key.start_with?("!") => value } }
|
38
|
+
else
|
39
|
+
{ key => value }
|
34
40
|
end
|
41
|
+
}.reduce do |variants, more_variants|
|
42
|
+
variants.merge!(more_variants) { |_key, v1, v2| v1.merge!(v2) }
|
35
43
|
end
|
36
|
-
|
37
|
-
result.join " "
|
38
44
|
end
|
39
|
-
end
|
45
|
+
end
|
data/lib/class_variants.rb
CHANGED
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-12-21 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: []
|