classy-yaml 0.8.5 → 1.1

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: 1a317b7d0d4d98ba75bede21873cab424ae0238336fbd61a3425240d9972824a
4
- data.tar.gz: e42bba9cb118a3805da435e1737bad5000ca1b181104eb5ddfabc194f7472ebd
3
+ metadata.gz: dda6808c6932b7207c7c1904f4d797cd854532d6bde8e399358571a4b9d5e0b2
4
+ data.tar.gz: 69db95341f9669126246d13e77ee3647fc0b47a79516dda1f314598e7752d42f
5
5
  SHA512:
6
- metadata.gz: 3dce1e8ae1e7174381890149634d25b820f46d786451cc128437a8b5e960bc6f5729d9b38de6ad7ceb712494dee3237d04d3b5658b27730c9110de0608dbea26
7
- data.tar.gz: 15740e73a3143adc07ef903f7dfebf31e3bb20ef89b621776f207b1e9afa5874b314be84dc8df1ebf90f48fb9a7603ac956cf8c02f0327ee399711e73557c45a
6
+ metadata.gz: 9356e475faf159ce5d4bfc416021b5fc0dbc3b02050dbceb31629eee7d5aee315365f59b19baae20b1108a74f74f3ec7bf57b7df5b93b7d899dd702b44c0c245
7
+ data.tar.gz: 6ef3431328fb368bd12dbbf458154936ecc3520c58f7884edf34c0037812266fbdb4db11ae42bbb4a57b9d84daf88efbc54a429df797c663883e3d6963648ac5
data/README.md CHANGED
@@ -72,6 +72,20 @@ btn:
72
72
 
73
73
  # will add the classes "px-3 py-2 text-blue-50"
74
74
  ```
75
+ ## Configuration
76
+ You can configure the gem by creating an initializer in your Rails app. The following options are available:
77
+
78
+ ```ruby
79
+ Classy::Yaml.setup do |config|
80
+ # The default path for the utility classes YAML file
81
+ config.default_path = "config/utility_classes.yml"
82
+
83
+ # Any extra files you want to load in addition to the default file. The last file loaded will overwrite any previous definitions
84
+ config.extra_files = [
85
+ "app/yamls/extra_styles.yml"
86
+ ]
87
+ end
88
+ ```
75
89
 
76
90
  ## Installation
77
91
  Add this line to your application's Gemfile:
@@ -98,7 +112,7 @@ purge: [
98
112
  ]
99
113
  ```
100
114
  ## 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 enought to be worth publishing.
115
+ 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
116
 
103
117
  ## License
104
118
  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
- classy_file = if Dir.exist?("#{calling_path}/#{calling_file}")
10
- "#{calling_path}/#{calling_file}/#{component_name}.yml"
11
- else
12
- "#{calling_path}/#{component_name}.yml"
13
- end
14
- helpers.yass(args, classy_files: [classy_file] )
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
@@ -3,15 +3,14 @@ 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.exist?(Rails.root.join("config/utility_classes.yml"))
7
-
8
- classy_files_hash = args.find { |arg| arg.is_a?(Hash) && arg.keys.include?(:classy_files) }
9
- if classy_files_hash.present?
10
- classy_files_hash[:classy_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
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
 
@@ -26,7 +25,7 @@ module Classy
26
25
  private
27
26
 
28
27
  def flatten_args(root: [], values: [], keys: [], added_classes: [])
29
- values.each do|value|
28
+ values.each do |value|
30
29
  if value.is_a?(Hash)
31
30
  if value.has_key? :add
32
31
  added_classes << value[:add]
@@ -64,7 +63,7 @@ module Classy
64
63
  classy_yaml.send(:dig, *(key[0...-1] + ['base'])).try(:split, " ")
65
64
  end
66
65
  rescue
67
- raise Classy::Yaml::InvalidKeyError.new(data: key)
66
+ Rails.logger.warn(Classy::Yaml::InvalidKeyError.new(data: key))
68
67
  end
69
68
 
70
69
  begin
@@ -75,7 +74,7 @@ module Classy
75
74
  base_classes = nil if base_classes.blank?
76
75
  fetched_classes = nil if fetched_classes.blank?
77
76
  rescue
78
- raise Classy::Yaml::InvalidKeyError.new(data: key)
77
+ Rails.logger.warn(Classy::Yaml::InvalidKeyError.new(data: key))
79
78
  end
80
79
  end
81
80
 
@@ -1,5 +1,5 @@
1
1
  module Classy
2
2
  module Yaml
3
- VERSION = '0.8.5'
3
+ VERSION = '1.1'
4
4
  end
5
5
  end
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: 0.8.5
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tonksthebear
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2024-03-22 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.2.26
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: []