class_variants 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/class_variants.rb +39 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a0d49412628b8d47161a0687b06d95d11728e15d2ac3f311b68e91023c29d3e
|
4
|
+
data.tar.gz: c4e984bbfa5d0378d918acc7e4fc188957933a49d109788ec5affb54f8681194
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f37d9c9e5e03405fd9eb6e559fb5b9c70e5cf97aa1d74d51029b9ac1d816cff544c4c576920e42dd28e5a5fd661420025a3cea24095a51ee4f3dc09f576938ed
|
7
|
+
data.tar.gz: 46fb46e7b181571f94118530e6181ebf906e0643d875200a0125319c27c242723db11977f135a5e3467e248c9ed314d2a48ee5e5d99c17bceb9ba03ce6b7647a
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ClassVariants
|
2
|
+
attr_reader :classes
|
3
|
+
attr_reader :variants
|
4
|
+
attr_reader :defaults
|
5
|
+
|
6
|
+
def initialize(classes = "", variants: {}, defaults: {})
|
7
|
+
@classes = classes
|
8
|
+
@variants = variants
|
9
|
+
@defaults = defaults
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(**settings)
|
13
|
+
result = []
|
14
|
+
|
15
|
+
# Add the default classes if any provided
|
16
|
+
result << classes if classes
|
17
|
+
|
18
|
+
# Keep the applied variants so we can later apply the defaults
|
19
|
+
applied_options = []
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
if defaults.present?
|
30
|
+
defaults.each do |key, key_to_use|
|
31
|
+
unless applied_options.include? key
|
32
|
+
result << @variants[key][key_to_use] if @variants[key].present?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
result.join " "
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: class_variants
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Marin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Easily configure styles and apply them as classes.
|
14
|
+
email: adrian@adrianthedev.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/class_variants.rb
|
20
|
+
homepage: https://github.com/avo-hq/class_variants
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata:
|
24
|
+
bug_tracker_uri: https://github.com/avo-hq/class_variants/issues
|
25
|
+
homepage_uri: https://github.com/avo-hq/class_variants
|
26
|
+
source_code_uri: https://github.com/avo-hq/class_variants
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.3.3
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Easily configure styles and apply them as classes.
|
46
|
+
test_files: []
|