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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8217df31105dafb708cece0e3d7799cd2bc9515af19b1c1377fc2e25d633001
4
- data.tar.gz: 37ad98554aa926df73668bc9f1bbdbf5507c322bf27140baeb9bb12083423e48
3
+ metadata.gz: ecb27c17050e3f5ca77111089257465fa14c8f92c31f88758690c3aa0c62c672
4
+ data.tar.gz: cbad509cfd4a1f1dd4fb2fa99aca28c7ca9e0566eeb9596e839696d4b73b409b
5
5
  SHA512:
6
- metadata.gz: ec20f6a773530cc1d4a62288d4909f9e09d217bae6d3e0a0edd3813ad6eade8eaf41e73f5c25937507124d21bde8b1a6d23fc80a7626bd1add3e2e6161cdb586
7
- data.tar.gz: 72b913d23ca606d4b2ac79caeb5a14afd8cdbf00362d99e2281262d4c48d626dc51acbda4ef333ff83f597fc5d74c48383cbe5730dabe007b1f3060ff5a7a9da
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 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
 
@@ -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 = calling_path + "/" + component_name + ".yml"
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
@@ -5,6 +5,10 @@ module Classy
5
5
  config.to_prepare do
6
6
  ApplicationController.helper(Classy::Yaml::Helpers)
7
7
  end
8
+
9
+ Gem.loaded_specs['classy-yaml'].dependencies.each do |d|
10
+ require d.name if Rails.env.test?
11
+ end
8
12
  end
9
13
  end
10
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.1'
3
+ VERSION = '0.6.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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
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 00:00:00.000000000 Z
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