classy-yaml 1.4.0 → 1.5.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: 8a6e53b93d281f5b22bc929c6b1df6f389fcd81ed4bc8b9bd3710830a1974ed1
4
- data.tar.gz: 0702b4fe219583b61140e89487fb0f42c87b4f6de1c2b5889cbacc7186d546b2
3
+ metadata.gz: b91dad78932d510d2299faae67a08584bad33501c3a048435603a6e673049090
4
+ data.tar.gz: c3d9d4e2c543e3f3b70b94260f2293d5d3f6a24474e228690aa5c97f5a80666f
5
5
  SHA512:
6
- metadata.gz: ef1645ba8e34171a8b2a4eb24830789f5d3d412445e2bca83b6e30285a3a20fdd0911ac65388e092cd44197c3e1b9980bc0b565c8d4e623f72671c678ba1935f
7
- data.tar.gz: c62c9a28bb4dc589fe04838f5ed33b6fcf27ee2dc68c833161f8e8a57ead9421ef78705c31f8baa546921de1366e247be4f3caf6e9e122720f428940a94e6246
6
+ metadata.gz: 1bc0b46c0d2f9fb2a49eedada6e497c7aebf14bc6f95f75609461620f44d5df12066dd8437fe8be90240053670dad19bf6cf1a80a1d8a3f08f0a54ea8e1ce6ad
7
+ data.tar.gz: bcf8f2d58c819e91a935076eb920094e27b2855e30d13038fd26ad3942447d1c5c14f646427e18d3787a6c39774da89bc63443995cf0373935eceb28db0186b4
@@ -2,13 +2,13 @@ module Classy
2
2
  module Yaml
3
3
  module ComponentHelpers
4
4
  def yass(*args)
5
- calling_path = Object.const_source_location(self.class.name).first.split('/')[0...-1].join('/')
6
- calling_file = Object.const_source_location(self.class.name).first.split('/').last.split('.').first
7
- component_name = self.class.name.underscore.split('/').last.split('.').first
5
+ calling_path = Object.const_source_location(self.class.name).first.split("/")[0...-1].join("/")
6
+ calling_file = Object.const_source_location(self.class.name).first.split("/").last.split(".").first
7
+ component_name = self.class.name.underscore.split("/").last.split(".").first
8
8
 
9
- classy_files = ["#{calling_path}/#{component_name}.yml",
9
+ classy_files = [ "#{calling_path}/#{component_name}.yml",
10
10
  "#{calling_path}/#{calling_file}/#{calling_file}.yml",
11
- "#{calling_path}/#{calling_file}/#{component_name}.yml"]
11
+ "#{calling_path}/#{calling_file}/#{component_name}.yml" ]
12
12
 
13
13
  if args.first.is_a?(Hash)
14
14
  args.first.merge!({ classy_files: classy_files.uniq })
@@ -47,8 +47,8 @@ module Classy
47
47
  begin
48
48
  path_obj = file_path.is_a?(Pathname) ? file_path : Rails.root.join(file_path)
49
49
  if File.exist?(path_obj)
50
- content = File.read(path_obj, encoding: 'UTF-8')
51
- parsed_yaml = YAML.safe_load(content, permitted_classes: [Symbol, String, Array, Hash], aliases: true)
50
+ content = File.read(path_obj, encoding: "UTF-8")
51
+ parsed_yaml = YAML.safe_load(content, permitted_classes: [ Symbol, String, Array, Hash ], aliases: true)
52
52
  classy_yamls << parsed_yaml if parsed_yaml && parsed_yaml.is_a?(Hash)
53
53
  end
54
54
  rescue Psych::SyntaxError => e
@@ -73,14 +73,14 @@ module Classy
73
73
  end
74
74
 
75
75
  value.keys.each do |key|
76
- values << (root + [key.to_s])
77
- flatten_args(root: root + [key.to_s], values: [value[key]], keys: keys, added_classes: added_classes)
76
+ values << (root + [ key.to_s ])
77
+ flatten_args(root: root + [ key.to_s ], values: [ value[key] ], keys: keys, added_classes: added_classes)
78
78
  end
79
79
  else
80
80
  if value.is_a?(Array)
81
81
  flatten_args(root: root, values: value, keys: keys, added_classes: added_classes)
82
82
  else
83
- keys << (root + [value.to_s])
83
+ keys << (root + [ value.to_s ])
84
84
  end
85
85
  end
86
86
  end
@@ -106,12 +106,12 @@ module Classy
106
106
  begin
107
107
  value_at_key = classy_yaml.send(:dig, *key)
108
108
  base_value = if value_at_key.is_a?(Hash)
109
- classy_yaml.send(:dig, *(key + ['base']))
110
- elsif key.length > 1
111
- classy_yaml.send(:dig, *(key[0...-1] + ['base']))
112
- else
109
+ classy_yaml.send(:dig, *(key + [ "base" ]))
110
+ elsif key.length > 1
111
+ classy_yaml.send(:dig, *(key[0...-1] + [ "base" ]))
112
+ else
113
113
  nil
114
- end
114
+ end
115
115
  normalized_base = normalize_original(base_value)
116
116
  base_classes ||= normalized_base
117
117
  rescue
@@ -1,5 +1,5 @@
1
1
  module Classy
2
2
  module Yaml
3
- VERSION = '1.4.0'
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
data/lib/classy/yaml.rb CHANGED
@@ -13,6 +13,9 @@ module Classy
13
13
  mattr_accessor :extra_files
14
14
  @@extra_files = []
15
15
 
16
+ mattr_accessor :override_tag_helpers
17
+ @@override_tag_helpers = false
18
+
16
19
  # -- Autoloads --
17
20
  autoload :Helpers, "classy/yaml/helpers"
18
21
  autoload :ComponentHelpers, "classy/yaml/component_helpers"
@@ -39,6 +42,11 @@ module Classy
39
42
  @cached_default_yaml = nil # Clear cache on reassignment
40
43
  end
41
44
 
45
+ def self.override_tag_helpers=(value)
46
+ @@override_tag_helpers = value
47
+ apply_tag_helper_override if value
48
+ end
49
+
42
50
  # -- Cached Data Accessors (Lazy Loading) --
43
51
  def self.cached_engine_yamls
44
52
  # Bypass cache in development and test environments
@@ -73,18 +81,42 @@ module Classy
73
81
  # Clear all caches when configuration changes
74
82
  @cached_engine_yamls = nil
75
83
  @cached_default_yaml = nil
84
+ # Apply tag helper override if enabled
85
+ apply_tag_helper_override if @@override_tag_helpers
76
86
  end
77
87
 
78
88
  private
79
89
 
80
- # -- Private Loading Methods --
90
+ def self.apply_tag_helper_override
91
+ return unless defined?(ActionView::Helpers::TagHelper)
92
+
93
+ # Override the TagBuilder class which is what the tag method returns
94
+ ActionView::Helpers::TagHelper::TagBuilder.class_eval do
95
+ unless method_defined?(:classy_yaml_original_tag_options)
96
+ alias_method :classy_yaml_original_tag_options, :tag_options
97
+
98
+ def tag_options(options, escape = true)
99
+ if options
100
+ class_key = options.key?(:class) ? :class : "class"
101
+ options = options.dup
102
+ val = options[class_key]
103
+ if val.is_a?(Symbol) || val.is_a?(Hash) || val.is_a?(Array)
104
+ options[:class] = yass(val)
105
+ end
106
+ end
107
+ classy_yaml_original_tag_options(options, escape)
108
+ end
109
+ end
110
+ end
111
+ end
112
+
81
113
  def self.load_engine_yamls
82
114
  yamls = []
83
115
  self.engine_files.each do |file_path|
84
116
  begin
85
117
  if File.exist?(file_path)
86
- content = File.read(file_path, encoding: 'UTF-8')
87
- parsed_yaml = YAML.safe_load(content, permitted_classes: [Symbol, String, Array, Hash], aliases: true)
118
+ content = File.read(file_path, encoding: "UTF-8")
119
+ parsed_yaml = YAML.safe_load(content, permitted_classes: [ Symbol, String, Array, Hash ], aliases: true)
88
120
  yamls << parsed_yaml if parsed_yaml && parsed_yaml.is_a?(Hash)
89
121
  end
90
122
  rescue Psych::SyntaxError => e
@@ -100,8 +132,8 @@ module Classy
100
132
  default_path = Rails.root.join(self.default_file)
101
133
  begin
102
134
  if File.exist?(default_path)
103
- content = File.read(default_path, encoding: 'UTF-8')
104
- parsed_yaml = YAML.safe_load(content, permitted_classes: [Symbol, String, Array, Hash], aliases: true)
135
+ content = File.read(default_path, encoding: "UTF-8")
136
+ parsed_yaml = YAML.safe_load(content, permitted_classes: [ Symbol, String, Array, Hash ], aliases: true)
105
137
  return parsed_yaml if parsed_yaml && parsed_yaml.is_a?(Hash)
106
138
  end
107
139
  rescue Psych::SyntaxError => e
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: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tonksthebear
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-31 00:00:00.000000000 Z
11
+ date: 2025-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport