classy-yaml 1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/classy/yaml/component_helpers.rb +9 -3
- data/lib/classy/yaml/helpers.rb +15 -12
- data/lib/classy/yaml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cb94b02acbc1f92548d666eb321fe7b06e68828c2cb6d53d5989f4435cd2c38
|
4
|
+
data.tar.gz: c52c21899d471cf246e4c1adf2571b88e405a42ac5ea5c3dd659a8cd4edfb918
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b989e46790ceb55f42bb802980e3ec5de7960b10818493646a911b204a0a6857c0d9a5053353c9b317a9c74a5317c3b9e343d889fd8fe7adb9b9af3284d914
|
7
|
+
data.tar.gz: 28013c5c0348754432641c55bbc7827f912c5ba9320bb9a7d3768c383bfcb3159a6e1cfbae476d545cabc87159145d4b27539e9c080eb4064e6ac97d0ffc7420
|
data/README.md
CHANGED
@@ -25,6 +25,19 @@ btn:
|
|
25
25
|
|
26
26
|
Now, calling `yass(btn: :blue)` or `yass(btn: :yellow)` will ALSO pull in the classes from `btn: :base`.
|
27
27
|
|
28
|
+
### Optionally Skipping Base
|
29
|
+
|
30
|
+
You can optionally skip including the base on a `yass` call by including the key/value `skip_base: true`. So, using the example above,
|
31
|
+
we can perform:
|
32
|
+
```
|
33
|
+
btn:
|
34
|
+
base: "px-3 py-2"
|
35
|
+
blue: "text-blue-200 bg-blue-500"
|
36
|
+
yellow: "text-yellow-200 bg-blue-500"
|
37
|
+
```
|
38
|
+
|
39
|
+
Now, calling `yass(btn: :blue, skip_base: true)` and this will skip pulling in the classes from `btn: :base`. This is helpful
|
40
|
+
when defining animation classes and you only want to include the different classes, such as `active` and `inactive` for instance.
|
28
41
|
|
29
42
|
### ViewComponent
|
30
43
|
There is a special helper built for ViewComponent and sidecar assets. In your `example_component.rb`, add the line `include Classy::Yaml::ComponentHelpers`. This helper will tell `yass` to check if there is a `example_component.yml` file, and first use that for definitions. If the definitions aren't found in the `example_component.yml`, then it will fallback to `config/utility_classes.yml`.
|
@@ -7,11 +7,17 @@ module Classy
|
|
7
7
|
component_name = self.class.name.underscore.split("/").last.split(".").first
|
8
8
|
|
9
9
|
classy_files = ["#{calling_path}/#{component_name}.yml",
|
10
|
-
|
11
|
-
|
10
|
+
"#{calling_path}/#{calling_file}/#{calling_file}.yml",
|
11
|
+
"#{calling_path}/#{calling_file}/#{component_name}.yml"
|
12
12
|
]
|
13
13
|
|
14
|
-
|
14
|
+
if args.first.is_a?(Hash)
|
15
|
+
args.first.merge!({ classy_files: classy_files.uniq })
|
16
|
+
else
|
17
|
+
args << { classy_files: classy_files.uniq }
|
18
|
+
end
|
19
|
+
|
20
|
+
helpers.yass(*args)
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/classy/yaml/helpers.rb
CHANGED
@@ -16,8 +16,9 @@ module Classy
|
|
16
16
|
|
17
17
|
return if classy_yamls.blank?
|
18
18
|
|
19
|
+
skip_base_hash = args.find { |arg| arg.is_a?(Hash) && arg.keys.include?(:skip_base) } || {}
|
19
20
|
keys, classes = flatten_args(values: args)
|
20
|
-
classes += fetch_classes(keys, classy_yamls: classy_yamls)
|
21
|
+
classes += fetch_classes(keys, classy_yamls: classy_yamls, skip_base: skip_base_hash[:skip_base])
|
21
22
|
|
22
23
|
return classes.flatten.join(" ")
|
23
24
|
end
|
@@ -48,7 +49,7 @@ module Classy
|
|
48
49
|
return keys, added_classes
|
49
50
|
end
|
50
51
|
|
51
|
-
def fetch_classes(keys, classy_yamls: [])
|
52
|
+
def fetch_classes(keys, classy_yamls: [], skip_base: false)
|
52
53
|
classes = []
|
53
54
|
|
54
55
|
keys.map do |key|
|
@@ -56,14 +57,16 @@ module Classy
|
|
56
57
|
fetched_classes = nil
|
57
58
|
|
58
59
|
classy_yamls.reverse_each do |classy_yaml|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
unless skip_base == true
|
61
|
+
begin
|
62
|
+
base_classes ||= if classy_yaml.send(:dig, *key).is_a?(Hash)
|
63
|
+
classy_yaml.send(:dig, *(key + ['base'])).try(:split, " ")
|
64
|
+
else
|
65
|
+
classy_yaml.send(:dig, *(key[0...-1] + ['base'])).try(:split, " ")
|
66
|
+
end
|
67
|
+
rescue
|
68
|
+
Rails.logger.warn(Classy::Yaml::InvalidKeyError.new(data: key))
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
72
|
begin
|
@@ -78,8 +81,8 @@ module Classy
|
|
78
81
|
end
|
79
82
|
end
|
80
83
|
|
81
|
-
classes << base_classes
|
82
|
-
classes << fetched_classes
|
84
|
+
classes << base_classes unless base_classes.blank?
|
85
|
+
classes << fetched_classes unless fetched_classes.blank?
|
83
86
|
end
|
84
87
|
|
85
88
|
classes.reject!(&:blank?)
|
data/lib/classy/yaml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy-yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tonksthebear
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|