classy-yaml 0.8.5 → 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 +28 -1
- data/lib/classy/yaml/component_helpers.rb +6 -6
- data/lib/classy/yaml/helpers.rb +25 -23
- data/lib/classy/yaml/version.rb +1 -1
- data/lib/classy/yaml.rb +14 -0
- metadata +6 -6
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`.
|
@@ -72,6 +85,20 @@ btn:
|
|
72
85
|
|
73
86
|
# will add the classes "px-3 py-2 text-blue-50"
|
74
87
|
```
|
88
|
+
## Configuration
|
89
|
+
You can configure the gem by creating an initializer in your Rails app. The following options are available:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Classy::Yaml.setup do |config|
|
93
|
+
# The default path for the utility classes YAML file
|
94
|
+
config.default_path = "config/utility_classes.yml"
|
95
|
+
|
96
|
+
# Any extra files you want to load in addition to the default file. The last file loaded will overwrite any previous definitions
|
97
|
+
config.extra_files = [
|
98
|
+
"app/yamls/extra_styles.yml"
|
99
|
+
]
|
100
|
+
end
|
101
|
+
```
|
75
102
|
|
76
103
|
## Installation
|
77
104
|
Add this line to your application's Gemfile:
|
@@ -98,7 +125,7 @@ purge: [
|
|
98
125
|
]
|
99
126
|
```
|
100
127
|
## Contributing
|
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
|
128
|
+
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 enough to be worth publishing.
|
102
129
|
|
103
130
|
## License
|
104
131
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -6,12 +6,12 @@ module Classy
|
|
6
6
|
calling_file = self.class.source_location.split("/").last.split(".").first
|
7
7
|
component_name = self.class.name.underscore.split("/").last.split(".").first
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
helpers.yass(args, classy_files:
|
9
|
+
classy_files = ["#{calling_path}/#{component_name}.yml",
|
10
|
+
"#{calling_path}/#{calling_file}/#{calling_file}.yml",
|
11
|
+
"#{calling_path}/#{calling_file}/#{component_name}.yml"
|
12
|
+
]
|
13
|
+
|
14
|
+
helpers.yass(args, classy_files: classy_files.uniq)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/classy/yaml/helpers.rb
CHANGED
@@ -3,22 +3,22 @@ module Classy
|
|
3
3
|
module Helpers
|
4
4
|
def yass(*args)
|
5
5
|
classy_yamls = []
|
6
|
-
classy_yamls << YAML.load_file(Rails.root.join(
|
7
|
-
|
8
|
-
classy_files_hash = args.find { |arg| arg.is_a?(Hash) && arg.keys.include?(:classy_files) }
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
6
|
+
classy_yamls << YAML.load_file(Rails.root.join(Classy::Yaml.default_file)) if File.exist?(Rails.root.join(Classy::Yaml.default_file))
|
7
|
+
|
8
|
+
classy_files_hash = args.find { |arg| arg.is_a?(Hash) && arg.keys.include?(:classy_files) } || { classy_files: [] }
|
9
|
+
|
10
|
+
(classy_files_hash[:classy_files] + Classy::Yaml.extra_files).each do |file|
|
11
|
+
if File.exist?(file) && YAML.load_file(file)
|
12
|
+
file = YAML.load_file(file)
|
13
|
+
classy_yamls << file if file
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
return if classy_yamls.blank?
|
19
18
|
|
19
|
+
skip_base_hash = args.find { |arg| arg.is_a?(Hash) && arg.keys.include?(:skip_base) } || {}
|
20
20
|
keys, classes = flatten_args(values: args)
|
21
|
-
classes += fetch_classes(keys, classy_yamls: classy_yamls)
|
21
|
+
classes += fetch_classes(keys, classy_yamls: classy_yamls, skip_base: skip_base_hash[:skip_base])
|
22
22
|
|
23
23
|
return classes.flatten.join(" ")
|
24
24
|
end
|
@@ -26,7 +26,7 @@ module Classy
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def flatten_args(root: [], values: [], keys: [], added_classes: [])
|
29
|
-
values.each do|value|
|
29
|
+
values.each do |value|
|
30
30
|
if value.is_a?(Hash)
|
31
31
|
if value.has_key? :add
|
32
32
|
added_classes << value[:add]
|
@@ -49,7 +49,7 @@ module Classy
|
|
49
49
|
return keys, added_classes
|
50
50
|
end
|
51
51
|
|
52
|
-
def fetch_classes(keys, classy_yamls: [])
|
52
|
+
def fetch_classes(keys, classy_yamls: [], skip_base: false)
|
53
53
|
classes = []
|
54
54
|
|
55
55
|
keys.map do |key|
|
@@ -57,14 +57,16 @@ 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
|
-
|
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
|
68
70
|
end
|
69
71
|
|
70
72
|
begin
|
@@ -75,12 +77,12 @@ module Classy
|
|
75
77
|
base_classes = nil if base_classes.blank?
|
76
78
|
fetched_classes = nil if fetched_classes.blank?
|
77
79
|
rescue
|
78
|
-
|
80
|
+
Rails.logger.warn(Classy::Yaml::InvalidKeyError.new(data: key))
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
|
-
classes << base_classes
|
83
|
-
classes << fetched_classes
|
84
|
+
classes << base_classes unless base_classes.blank?
|
85
|
+
classes << fetched_classes unless fetched_classes.blank?
|
84
86
|
end
|
85
87
|
|
86
88
|
classes.reject!(&:blank?)
|
data/lib/classy/yaml/version.rb
CHANGED
data/lib/classy/yaml.rb
CHANGED
@@ -3,8 +3,22 @@ require "classy/yaml/engine"
|
|
3
3
|
|
4
4
|
module Classy
|
5
5
|
module Yaml
|
6
|
+
mattr_accessor :default_file
|
7
|
+
@@default_file = "config/utility_classes.yml"
|
8
|
+
|
9
|
+
mattr_accessor :extra_files
|
10
|
+
@@extra_files = []
|
11
|
+
|
6
12
|
autoload :Helpers, "classy/yaml/helpers"
|
7
13
|
autoload :ComponentHelpers, "classy/yaml/component_helpers"
|
8
14
|
autoload :InvalidKeyError, "classy/yaml/invalid_key_error"
|
15
|
+
|
16
|
+
def self.extra_files=(value)
|
17
|
+
@@extra_files = Array.wrap(value).reject(&:blank?).map { |file| Rails.root.join(file) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.setup
|
21
|
+
yield self
|
22
|
+
end
|
9
23
|
end
|
10
24
|
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:
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tonksthebear
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -105,7 +105,7 @@ metadata:
|
|
105
105
|
homepage_uri: https://github.com/Tonksthebear/classy-yaml
|
106
106
|
source_code_uri: https://github.com/Tonksthebear/classy-yaml
|
107
107
|
changelog_uri: https://github.com/Tonksthebear/classy-yaml/releases
|
108
|
-
post_install_message:
|
108
|
+
post_install_message:
|
109
109
|
rdoc_options: []
|
110
110
|
require_paths:
|
111
111
|
- lib
|
@@ -120,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
124
|
-
signing_key:
|
123
|
+
rubygems_version: 3.4.1
|
124
|
+
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Rails helper to allow yaml configuration of utility css classes
|
127
127
|
test_files: []
|