classy-yaml 1.1 → 1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dda6808c6932b7207c7c1904f4d797cd854532d6bde8e399358571a4b9d5e0b2
4
- data.tar.gz: 69db95341f9669126246d13e77ee3647fc0b47a79516dda1f314598e7752d42f
3
+ metadata.gz: 18499d16c6513652c6424bf8ff1cf2ec887b26a50a28f1d1a16b317f74a63ce4
4
+ data.tar.gz: ee602d76c693f54041c07548c5634760c9ccba8c74746177d7d22207148a590f
5
5
  SHA512:
6
- metadata.gz: 9356e475faf159ce5d4bfc416021b5fc0dbc3b02050dbceb31629eee7d5aee315365f59b19baae20b1108a74f74f3ec7bf57b7df5b93b7d899dd702b44c0c245
7
- data.tar.gz: 6ef3431328fb368bd12dbbf458154936ecc3520c58f7884edf34c0037812266fbdb4db11ae42bbb4a57b9d84daf88efbc54a429df797c663883e3d6963648ac5
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`.
@@ -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
- begin
60
- base_classes ||= if classy_yaml.send(:dig, *key).is_a?(Hash)
61
- classy_yaml.send(:dig, *(key + ['base'])).try(:split, " ")
62
- else
63
- classy_yaml.send(:dig, *(key[0...-1] + ['base'])).try(:split, " ")
64
- end
65
- rescue
66
- Rails.logger.warn(Classy::Yaml::InvalidKeyError.new(data: key))
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?)
@@ -1,5 +1,5 @@
1
1
  module Classy
2
2
  module Yaml
3
- VERSION = '1.1'
3
+ VERSION = '1.2'
4
4
  end
5
5
  end
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.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-22 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport