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.
- checksums.yaml +4 -4
- data/lib/katalyst/html_attributes.rb +38 -13
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22dc61eb82f19345cd8a5b4e2929cb74b41578fe37950629f37219cd85e958ab
|
4
|
+
data.tar.gz: 72168e12c5d010ec54233e5fb89933c77ebef08fc121c6a559feb0e2462f4cad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1db494a3f7b7d503455df70b2dfb3ee593c2954e4b04d2fea91dfd919ebdb8582239b1b0366c4891e64719b44b0a68777083fa3ea4e0899bb8a9b725c91d62e
|
7
|
+
data.tar.gz: 781b25b38f0d78c0ddb7e517663feba486ca6ad3e15eab41eefaef3f252cdf370344309376ddefa9c12cb52bd659dc53950ab89c88c90353c014bd7693e20f85
|
@@ -1,35 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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
|
-
|
11
|
+
autoload :HasHtmlAttributes
|
10
12
|
|
11
|
-
|
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
|
-
|
18
|
-
|
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
|
-
|
23
|
+
html_attributes_get(ivar, default_method)
|
22
24
|
end
|
23
25
|
|
24
26
|
define_method(:"#{name}=") do |options|
|
25
|
-
|
27
|
+
html_attributes_set(ivar, options)
|
26
28
|
end
|
27
29
|
|
28
30
|
define_method(:"update_#{name}") do |**options, &block|
|
29
|
-
|
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.
|
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-
|
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.
|
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: []
|