classy-yaml 1.1 → 1.2
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/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: 18499d16c6513652c6424bf8ff1cf2ec887b26a50a28f1d1a16b317f74a63ce4
|
4
|
+
data.tar.gz: ee602d76c693f54041c07548c5634760c9ccba8c74746177d7d22207148a590f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16aa91f99106e901e9561f5e1d41a454999dfaefdeac7557becbc6d1ecf32cec6a6d306c2904b8981b2efbb75e7ca2bfd74af4b96521a37a3ae5ae9b0ece8fbb
|
7
|
+
data.tar.gz: 8696d46b02167e605ecaa5d74117f51dae9563595f9b87c94cf5f856b39bb979df19d5414e9e36924b99ba45bb4579d51741d02d9fab159fdd5595c6e2852236
|
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`.
|
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: '1.
|
4
|
+
version: '1.2'
|
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
|