classy-yaml 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 268a5b342320d4be502ad562a4740625645394eba3d927b97c3bf2919b611a5a
4
- data.tar.gz: 4db1bc8ffbffed59fd5c60741614ac7e294be7e975a1b85fda472d0ab2319634
3
+ metadata.gz: e550c3f72e3974d27db9f90ce7ff91b76e717373fd3965e2e3621442b7cbbd16
4
+ data.tar.gz: 4bb718adfce915e86a357e91c8497de69a08e7e79ad6b14169d8f81ad0bcea4e
5
5
  SHA512:
6
- metadata.gz: b54b1fdb7ecaaccf4d9da488111ef2b40d54bf536d683667a7af12ad30bb3c5e0d372823612f41b6737f311be0fd231642fdfbd71c1331572649b67ce8a5f54c
7
- data.tar.gz: d715ccf782b6c54ee93eb7acb1cb804428ae9b2fbcb646088c4c9ee41a3ba0aa2663938d22867f6e33c2ffa556758f0715885601ceee7f91260291aef7984210
6
+ metadata.gz: ae98344136a170b10ffc6c507518832d60583d0e7555cf536333998270ad04e6be83b82d3b555969271787bfebb71eb21988fe2b5a48c6924bd80725fd7f8167
7
+ data.tar.gz: 9277260199b1d3b84b13739f72b28ae1f4d93bb2c45b7e3fe330ed4fcffe15fac9ca9f6b338b4953ac259b464735e7f13e18b0a929b5a0668ab83714448ca57a
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 look for the definitions in the yaml file `config/utility_classes.yml` (note: you must add this yourself).
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
 
@@ -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).
@@ -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 = calling_path + "/" + component_name + ".yml"
8
-
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
@@ -1,7 +1,8 @@
1
+ require "rails"
2
+
1
3
  module Classy
2
4
  module Yaml
3
- class Engine < ::Rails::Engine
4
- paths["lib/classy/yaml"]
5
+ class Engine < Rails::Railtie
5
6
  config.to_prepare do
6
7
  ApplicationController.helper(Classy::Yaml::Helpers)
7
8
  end
@@ -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.exists?(Rails.root.join("config/utility_classes.yml"))
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.exists?(file) && YAML.load_file(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
- 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
-
66
- fetched_classes ||= unless classy_yaml.send(:dig, *key).is_a?(Hash)
67
- classy_yaml.send(:dig, *key).try(:split, " ")
68
- end
69
-
70
- base_classes = nil if base_classes.blank?
71
- fetched_classes = nil if fetched_classes.blank?
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
@@ -1,5 +1,5 @@
1
1
  module Classy
2
2
  module Yaml
3
- VERSION = '0.5.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
data/lib/classy/yaml.rb CHANGED
@@ -5,5 +5,6 @@ module Classy
5
5
  module Yaml
6
6
  autoload :Helpers, "classy/yaml/helpers"
7
7
  autoload :ComponentHelpers, "classy/yaml/component_helpers"
8
+ autoload :InvalidKeyError, "classy/yaml/invalid_key_error"
8
9
  end
9
10
  end
metadata CHANGED
@@ -1,35 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.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 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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
+ - - ">="
18
39
  - !ruby/object:Gem::Version
19
- version: 6.1.4
40
+ version: '6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
20
45
  - - ">="
21
46
  - !ruby/object:Gem::Version
22
- version: 6.1.4.1
47
+ version: '6'
23
48
  type: :runtime
24
49
  prerelease: false
25
50
  version_requirements: !ruby/object:Gem::Requirement
26
51
  requirements:
27
- - - "~>"
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
+ - - ">="
28
74
  - !ruby/object:Gem::Version
29
- version: 6.1.4
75
+ version: '3.36'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
30
80
  - - ">="
31
81
  - !ruby/object:Gem::Version
32
- version: 6.1.4.1
82
+ version: '3.36'
33
83
  description: Rails helper to allow yaml configuration of utility css classes
34
84
  email:
35
85
  - ''
@@ -44,6 +94,7 @@ files:
44
94
  - lib/classy/yaml/component_helpers.rb
45
95
  - lib/classy/yaml/engine.rb
46
96
  - lib/classy/yaml/helpers.rb
97
+ - lib/classy/yaml/invalid_key_error.rb
47
98
  - lib/classy/yaml/version.rb
48
99
  - lib/tasks/classy/yaml_tasks.rake
49
100
  homepage: https://github.com/Tonksthebear/classy-yaml