katalyst-html-attributes 1.1.0 → 1.1.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/katalyst/html_attributes.rb +38 -13
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c544198e07c9d144a3e9aceeb25e313c50363556996eb18676da0c833702e06d
4
- data.tar.gz: 78b155006b143e651facf97731065ef402151d20a00d1763f5f1228bfe03f5f8
3
+ metadata.gz: 22dc61eb82f19345cd8a5b4e2929cb74b41578fe37950629f37219cd85e958ab
4
+ data.tar.gz: 72168e12c5d010ec54233e5fb89933c77ebef08fc121c6a559feb0e2462f4cad
5
5
  SHA512:
6
- metadata.gz: 2dfd3e3ddfb9b4dddbc2cad16dac27132b63fc9e824acfd49db14f8c1f2a5aea02d3f989626f3d2debb75100eb4a88372d45b0f0fe222b7a537d7e8341e04b88
7
- data.tar.gz: e8c1041fbc322d54dae3b89643496d61a229394393dbec9b4cb40c5eedba9e532a529a5c72a1092061558cd5cc72ac16be74d6dc4033c9774cf9a5a76b968fcf
6
+ metadata.gz: e1db494a3f7b7d503455df70b2dfb3ee593c2954e4b04d2fea91dfd919ebdb8582239b1b0366c4891e64719b44b0a68777083fa3ea4e0899bb8a9b725c91d62e
7
+ data.tar.gz: 781b25b38f0d78c0ddb7e517663feba486ca6ad3e15eab41eefaef3f252cdf370344309376ddefa9c12cb52bd659dc53950ab89c88c90353c014bd7693e20f85
@@ -1,35 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "html_attributes/has_html_attributes"
3
+ require "active_support"
4
+ require "active_support/rails"
4
5
 
5
6
  module Katalyst
6
7
  module HtmlAttributes
8
+ extend ActiveSupport::Autoload
7
9
  extend ActiveSupport::Concern
8
10
 
9
- using HasHtmlAttributes
11
+ autoload :HasHtmlAttributes
10
12
 
11
- def self.options_to_html_attributes(options)
12
- options.slice(:id, :aria, :class, :data).merge_html(options.fetch(:html, {}))
13
- end
13
+ using HasHtmlAttributes
14
14
 
15
15
  class_methods do
16
16
  def define_html_attribute_methods(name, default: {})
17
- define_method(:"default_#{name}") { default }
18
- private(:"default_#{name}")
17
+ ivar = :"@#{name}"
18
+ default_method = :"default_#{name}"
19
+ define_method(default_method) { default.deep_dup }
20
+ private(default_method)
19
21
 
20
22
  define_method(name) do
21
- send(:"default_#{name}").merge_html(instance_variable_get(:"@#{name}") || {})
23
+ html_attributes_get(ivar, default_method)
22
24
  end
23
25
 
24
26
  define_method(:"#{name}=") do |options|
25
- instance_variable_set(:"@#{name}", HtmlAttributes.options_to_html_attributes(options))
27
+ html_attributes_set(ivar, options)
26
28
  end
27
29
 
28
30
  define_method(:"update_#{name}") do |**options, &block|
29
- attributes = instance_variable_get(:"@#{name}") || {}
30
- attributes = attributes.merge_html(HtmlAttributes.options_to_html_attributes(options))
31
- attributes = yield(attributes) if block
32
- instance_variable_set(:"@#{name}", attributes)
31
+ html_attributes_update(ivar, options, &block)
33
32
  end
34
33
  end
35
34
  end
@@ -43,5 +42,31 @@ module Katalyst
43
42
 
44
43
  self.html_attributes = options
45
44
  end
45
+
46
+ def options_to_html_attributes(options)
47
+ options.slice(:id, :aria, :class, :data).merge_html(options.fetch(:html, {}))
48
+ end
49
+ module_function(:options_to_html_attributes)
50
+
51
+ private
52
+
53
+ def html_attributes_get(ivar, default)
54
+ if instance_variable_defined?(ivar)
55
+ send(default).merge_html(instance_variable_get(ivar))
56
+ else
57
+ send(default)
58
+ end
59
+ end
60
+
61
+ def html_attributes_set(ivar, options)
62
+ instance_variable_set(ivar, options_to_html_attributes(options))
63
+ end
64
+
65
+ def html_attributes_update(ivar, options, &block)
66
+ attributes = instance_variable_get(ivar) || {}
67
+ attributes = attributes.merge_html(options_to_html_attributes(options))
68
+ attributes = yield(attributes) if block
69
+ instance_variable_set(ivar, attributes)
70
+ end
46
71
  end
47
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-html-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-13 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
41
+ description:
42
42
  email:
43
43
  - developers@katalyst.com.au
44
44
  executables: []
@@ -53,7 +53,7 @@ licenses:
53
53
  - MIT
54
54
  metadata:
55
55
  rubygems_mfa_required: 'true'
56
- post_install_message:
56
+ post_install_message:
57
57
  rdoc_options: []
58
58
  require_paths:
59
59
  - lib
@@ -68,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.5.9
72
- signing_key:
71
+ rubygems_version: 3.5.11
72
+ signing_key:
73
73
  specification_version: 4
74
74
  summary: HTML Attributes utilities for use with ViewComponents
75
75
  test_files: []