classy-yaml 0.5.1 → 0.8.0
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 -6
- data/lib/classy/yaml/component_helpers.rb +7 -4
- data/lib/classy/yaml/engine.rb +3 -2
- data/lib/classy/yaml/helpers.rb +22 -14
- 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 +61 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2bed093a5bc06fe6254b29ad1fa7bc10e0b23a790a009ab9f5efca6e4d21432
|
4
|
+
data.tar.gz: 321eb805f8a536ef82117e444c909036d006ede18acbb63b872451cb09588868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 151b2cc8b260fa4c6546128929b6dae28cbf932bb8540360bf5214db785c1c001506bcd685fc32db3e99f2462eb739ce029c2301eb676b1230b4b505b239dd5f
|
7
|
+
data.tar.gz: cc0b8fa3e737040917f2e05121f5600df4746565883b5d5783e0136519c783b6b97bcdbe702a6cd9d508b49fe34fb174cd74dc2ea1ded77694c1f83a0d289f71
|
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
|
|
@@ -46,12 +46,13 @@ btn:
|
|
46
46
|
|
47
47
|
# app/components/example_component/example_component.html.erb
|
48
48
|
|
49
|
-
<button class="<%=
|
49
|
+
<button class="<%=yass(btn: :purple)%>">Classy Button</button>
|
50
50
|
|
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:
|
@@ -67,12 +68,11 @@ btn:
|
|
67
68
|
|
68
69
|
# app/components/example_component/example_component.html.erb
|
69
70
|
|
70
|
-
<button class="<%=
|
71
|
+
<button class="<%=yass(btn: :purple)%>">Classy Button</button>
|
71
72
|
|
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
|
|
@@ -90,8 +90,15 @@ Or install it yourself as:
|
|
90
90
|
$ gem install classy-yaml
|
91
91
|
```
|
92
92
|
|
93
|
+
If using purging for styles, be sure to add the YAML files to the purge directories. For example, below is a tailwind.config.js:
|
94
|
+
```
|
95
|
+
purge: [
|
96
|
+
"./config/utility_classes.yml",
|
97
|
+
"./app/components/**/*.yml" // If using view component sidecar assets
|
98
|
+
]
|
99
|
+
```
|
93
100
|
## 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
|
101
|
+
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
102
|
|
96
103
|
## License
|
97
104
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -2,10 +2,13 @@ module Classy
|
|
2
2
|
module Yaml
|
3
3
|
module ComponentHelpers
|
4
4
|
def yass(*args)
|
5
|
-
component_name =
|
6
|
-
calling_path =
|
7
|
-
classy_file =
|
8
|
-
|
5
|
+
component_name = self.class.source_location.split("/").last.split(".").first
|
6
|
+
calling_path = self.class.source_location.split("/")[0...-1].join("/")
|
7
|
+
classy_file = if Dir.exist?("#{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
@@ -3,12 +3,12 @@ module Classy
|
|
3
3
|
module Helpers
|
4
4
|
def yass(*args)
|
5
5
|
classy_yamls = []
|
6
|
-
classy_yamls << YAML.load_file(Rails.root.join("config/utility_classes.yml")) if File.
|
6
|
+
classy_yamls << YAML.load_file(Rails.root.join("config/utility_classes.yml")) if File.exist?(Rails.root.join("config/utility_classes.yml"))
|
7
7
|
|
8
8
|
classy_files_hash = args.find { |arg| arg.is_a?(Hash) && arg.keys.include?(:classy_files) }
|
9
9
|
if classy_files_hash.present?
|
10
10
|
classy_files_hash[:classy_files].each do |file|
|
11
|
-
if File.
|
11
|
+
if File.exist?(file) && YAML.load_file(file)
|
12
12
|
file = YAML.load_file(file)
|
13
13
|
classy_yamls << file if file
|
14
14
|
end
|
@@ -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,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy-yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tonksthebear
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -24,6 +24,62 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: view_component
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: capybara
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.36'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.36'
|
27
83
|
description: Rails helper to allow yaml configuration of utility css classes
|
28
84
|
email:
|
29
85
|
- ''
|
@@ -38,6 +94,7 @@ files:
|
|
38
94
|
- lib/classy/yaml/component_helpers.rb
|
39
95
|
- lib/classy/yaml/engine.rb
|
40
96
|
- lib/classy/yaml/helpers.rb
|
97
|
+
- lib/classy/yaml/invalid_key_error.rb
|
41
98
|
- lib/classy/yaml/version.rb
|
42
99
|
- lib/tasks/classy/yaml_tasks.rake
|
43
100
|
homepage: https://github.com/Tonksthebear/classy-yaml
|
@@ -63,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
120
|
- !ruby/object:Gem::Version
|
64
121
|
version: '0'
|
65
122
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.2.26
|
67
124
|
signing_key:
|
68
125
|
specification_version: 4
|
69
126
|
summary: Rails helper to allow yaml configuration of utility css classes
|