classy-yaml 0.5.1 → 0.6.0
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 +4 -4
- data/README.md +4 -4
- data/lib/classy/yaml/component_helpers.rb +5 -2
- data/lib/classy/yaml/engine.rb +4 -0
- data/lib/classy/yaml/helpers.rb +20 -12
- data/lib/classy/yaml/invalid_key_error.rb +13 -0
- data/lib/classy/yaml/version.rb +1 -1
- data/lib/classy/yaml.rb +1 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecb27c17050e3f5ca77111089257465fa14c8f92c31f88758690c3aa0c62c672
|
4
|
+
data.tar.gz: cbad509cfd4a1f1dd4fb2fa99aca28c7ca9e0566eeb9596e839696d4b73b409b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01e0b9908f5ac755de537c709e4ba5ab4b214e207f93e90adffda0d7f7a770fbe8aa83160ec756ebba85e8a107bd89cdee53f2b79af86f128458067342fa792d
|
7
|
+
data.tar.gz: c5022b41e6db9d44e89d05131adffb5a81c69b4a8885ae1131267cb7715e1f4af719e62a4589e7f0d4db646fb726d51461bed75fbc0e4751f5824bbf0ed08b3e
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
This was created to provide convenient utility class grouping for environments without a bundler (or any situation where you might not want to add custom css classes). YAML files are a perfect structure for these situations.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
After installing the gem, the helper method `yass` will be available from anywhere. It
|
5
|
+
After installing the gem, the helper method `yass` will be available from anywhere. It looks for the definitions in the YAML file `config/utility_classes.yml` (note: you must add this yourself).
|
6
6
|
|
7
7
|
The YAML structure should follow this format:
|
8
8
|
|
@@ -51,7 +51,8 @@ btn:
|
|
51
51
|
# will add the classes "px-3 py-2 text-purple-200 bg-blue-500"
|
52
52
|
```
|
53
53
|
|
54
|
-
As you can see, this will merge definitions found in the ExampleComponent's sidecar asset with the main application's definitions. Not only will it merge, but it will overwrite them as well, allowing for true customization on a per-component basis:
|
54
|
+
As you can see, this will merge definitions found in the `ExampleComponent`'s sidecar asset with the main application's definitions. Not only will it merge, but it will overwrite them as well, allowing for true customization on a per-component basis:
|
55
|
+
|
55
56
|
```
|
56
57
|
# config/utility_classes.yml
|
57
58
|
btn:
|
@@ -72,7 +73,6 @@ btn:
|
|
72
73
|
# will add the classes "px-3 py-2 text-blue-50"
|
73
74
|
```
|
74
75
|
|
75
|
-
|
76
76
|
## Installation
|
77
77
|
Add this line to your application's Gemfile:
|
78
78
|
|
@@ -91,7 +91,7 @@ $ gem install classy-yaml
|
|
91
91
|
```
|
92
92
|
|
93
93
|
## Contributing
|
94
|
-
This is my first attempt at an actual gem usable for all. Any and all suggestions are absolutely welcome. I'm not the cleanest programmer, so code quality suggestions are welcome too 👍 I extracted this logic from my private work and I felt it was useful enought to be worth publishing
|
94
|
+
This is my first attempt at an actual gem usable for all. Any and all suggestions are absolutely welcome. I'm not the cleanest programmer, so code quality suggestions are welcome too 👍 I extracted this logic from my private work and I felt it was useful enought to be worth publishing.
|
95
95
|
|
96
96
|
## License
|
97
97
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -4,8 +4,11 @@ module Classy
|
|
4
4
|
def yass(*args)
|
5
5
|
component_name = caller.first.split("/").last.split(".").first
|
6
6
|
calling_path = caller.first.split("/")[0...-1].join("/")
|
7
|
-
classy_file =
|
8
|
-
|
7
|
+
classy_file = if Dir.exists?("#{calling_path}/#{component_name}")
|
8
|
+
"#{calling_path}/#{component_name}/#{component_name}.yml"
|
9
|
+
else
|
10
|
+
"#{calling_path}/#{component_name}.yml"
|
11
|
+
end
|
9
12
|
helpers.yass(args, classy_files: [classy_file] )
|
10
13
|
end
|
11
14
|
end
|
data/lib/classy/yaml/engine.rb
CHANGED
data/lib/classy/yaml/helpers.rb
CHANGED
@@ -57,18 +57,26 @@ module Classy
|
|
57
57
|
fetched_classes = nil
|
58
58
|
|
59
59
|
classy_yamls.reverse_each do |classy_yaml|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
60
|
+
begin
|
61
|
+
base_classes ||= if classy_yaml.send(:dig, *key).is_a?(Hash)
|
62
|
+
classy_yaml.send(:dig, *(key + ['base'])).try(:split, " ")
|
63
|
+
else
|
64
|
+
classy_yaml.send(:dig, *(key[0...-1] + ['base'])).try(:split, " ")
|
65
|
+
end
|
66
|
+
rescue
|
67
|
+
raise Classy::Yaml::InvalidKeyError.new(data: key)
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
fetched_classes ||= unless classy_yaml.send(:dig, *key).is_a?(Hash)
|
72
|
+
classy_yaml.send(:dig, *key).try(:split, " ")
|
73
|
+
end
|
74
|
+
|
75
|
+
base_classes = nil if base_classes.blank?
|
76
|
+
fetched_classes = nil if fetched_classes.blank?
|
77
|
+
rescue
|
78
|
+
raise Classy::Yaml::InvalidKeyError.new(data: key)
|
79
|
+
end
|
72
80
|
end
|
73
81
|
|
74
82
|
classes << base_classes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Classy
|
2
|
+
module Yaml
|
3
|
+
class InvalidKeyError < StandardError
|
4
|
+
def initialize(data)
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def message
|
9
|
+
"yass called with invalid keys: #{@data}. This error can be raised when calling nested keys on an un-nested root."
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/classy/yaml/version.rb
CHANGED
data/lib/classy/yaml.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: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tonksthebear
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: view_component
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.36'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.36'
|
27
55
|
description: Rails helper to allow yaml configuration of utility css classes
|
28
56
|
email:
|
29
57
|
- ''
|
@@ -38,6 +66,7 @@ files:
|
|
38
66
|
- lib/classy/yaml/component_helpers.rb
|
39
67
|
- lib/classy/yaml/engine.rb
|
40
68
|
- lib/classy/yaml/helpers.rb
|
69
|
+
- lib/classy/yaml/invalid_key_error.rb
|
41
70
|
- lib/classy/yaml/version.rb
|
42
71
|
- lib/tasks/classy/yaml_tasks.rake
|
43
72
|
homepage: https://github.com/Tonksthebear/classy-yaml
|