katalyst-html-attributes 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -0
- data/lib/katalyst/html_attributes.rb +18 -7
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c544198e07c9d144a3e9aceeb25e313c50363556996eb18676da0c833702e06d
|
4
|
+
data.tar.gz: 78b155006b143e651facf97731065ef402151d20a00d1763f5f1228bfe03f5f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dfd3e3ddfb9b4dddbc2cad16dac27132b63fc9e824acfd49db14f8c1f2a5aea02d3f989626f3d2debb75100eb4a88372d45b0f0fe222b7a537d7e8341e04b88
|
7
|
+
data.tar.gz: e8c1041fbc322d54dae3b89643496d61a229394393dbec9b4cb40c5eedba9e532a529a5c72a1092061558cd5cc72ac16be74d6dc4033c9774cf9a5a76b968fcf
|
data/README.md
CHANGED
@@ -30,3 +30,49 @@ class MyViewComponent < ViewComponent::Base
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
```
|
33
|
+
|
34
|
+
You can also define your own named attributes:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class MyViewComponent < ViewComponent::Base
|
38
|
+
include Katalyst::HtmlAttributes
|
39
|
+
|
40
|
+
define_html_attributes :link_attributes, :button_attributes
|
41
|
+
|
42
|
+
def initialize(link:, button:, **html_attributes)
|
43
|
+
super(**html_attributes)
|
44
|
+
|
45
|
+
update_link_attributes(**link) if link
|
46
|
+
update_button_attributes(**button) if button
|
47
|
+
end
|
48
|
+
|
49
|
+
def call
|
50
|
+
tag.div(**html_attributes) do
|
51
|
+
tag.a(**link_attributes) do
|
52
|
+
"Link"
|
53
|
+
end +
|
54
|
+
tag.button(**button_attributes) do
|
55
|
+
"Button"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_html_attributes
|
61
|
+
{
|
62
|
+
class: "my-class"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def default_link_attributes
|
67
|
+
{
|
68
|
+
class: "my-link"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def default_button_attributes
|
73
|
+
{
|
74
|
+
class: "my-button"
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
@@ -6,19 +6,30 @@ module Katalyst
|
|
6
6
|
module HtmlAttributes
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
using HasHtmlAttributes
|
10
|
+
|
11
|
+
def self.options_to_html_attributes(options)
|
12
|
+
options.slice(:id, :aria, :class, :data).merge_html(options.fetch(:html, {}))
|
13
|
+
end
|
11
14
|
|
15
|
+
class_methods do
|
12
16
|
def define_html_attribute_methods(name, default: {})
|
13
|
-
define_method("default_#{name}") { default }
|
14
|
-
private("default_#{name}")
|
17
|
+
define_method(:"default_#{name}") { default }
|
18
|
+
private(:"default_#{name}")
|
15
19
|
|
16
20
|
define_method(name) do
|
17
|
-
send("default_#{name}").merge_html(instance_variable_get("@#{name}") || {})
|
21
|
+
send(:"default_#{name}").merge_html(instance_variable_get(:"@#{name}") || {})
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method(:"#{name}=") do |options|
|
25
|
+
instance_variable_set(:"@#{name}", HtmlAttributes.options_to_html_attributes(options))
|
18
26
|
end
|
19
27
|
|
20
|
-
define_method("#{name}
|
21
|
-
|
28
|
+
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)
|
22
33
|
end
|
23
34
|
end
|
24
35
|
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.
|
4
|
+
version: 1.1.0
|
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:
|
11
|
+
date: 2024-05-13 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
|
@@ -61,15 +61,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '3.
|
64
|
+
version: '3.0'
|
65
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
71
|
+
rubygems_version: 3.5.9
|
72
|
+
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: HTML Attributes utilities for use with ViewComponents
|
75
75
|
test_files: []
|