vident 0.10.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/vident/base.rb +1 -0
- data/lib/vident/component.rb +1 -0
- data/lib/vident/root_component.rb +51 -10
- data/lib/vident/stable_id.rb +7 -1
- data/lib/vident/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 503019b8aac7501339acff5c350afbca9abb55599a696f348321554da15183c0
|
4
|
+
data.tar.gz: 175ffd2794c1b7c81bf879a8bb3c9f65c42fa16cc92748be77df255c0b5fdcff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c76ae38a7c66032e99b130e21d67ba52f6c9fc946e3476fc945b682e5916ad406f90c12e0db2ab189ddf961e8c4f1a6e2cd64fc7e79bd6464ea5ccb1387e0de
|
7
|
+
data.tar.gz: f25903b4f38418a6752f33190713f0d8c9b3f5c2e251fb83476a35b2894df4dc848a3e104c13cf1d10ad448e774f924194020781f23b2c6d9732b061e0351e34
|
data/CHANGELOG.md
CHANGED
@@ -14,6 +14,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
14
14
|
|
15
15
|
### Fixed
|
16
16
|
|
17
|
+
|
18
|
+
## [0.12.0] - 2024-02-25
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- `outlet` DSL methods updated so that the selector is scoped to the component's root element by default. This
|
23
|
+
is probably the most common use case, and it's now the default.
|
24
|
+
- `with_outlets` DSL method added to generate the data-* attributes for the outlets and return as a fragment
|
25
|
+
of HTML
|
26
|
+
|
27
|
+
|
28
|
+
## [0.11.0] - 2024-02-21
|
29
|
+
|
30
|
+
### Added
|
31
|
+
|
32
|
+
- `outlet_host` DSL method to support components hooking themselves into a host component's outlets
|
33
|
+
|
34
|
+
|
35
|
+
|
17
36
|
## [0.10.1] - 2024-02-21
|
18
37
|
|
19
38
|
### Added
|
data/lib/vident/base.rb
CHANGED
@@ -151,6 +151,7 @@ module Vident
|
|
151
151
|
actions: attribute(:actions) + Array.wrap(options[:actions]),
|
152
152
|
targets: attribute(:targets) + Array.wrap(options[:targets]),
|
153
153
|
outlets: attribute(:outlets) + Array.wrap(options[:outlets]),
|
154
|
+
outlet_host: attribute(:outlet_host),
|
154
155
|
named_classes: merge_stimulus_option(options, :named_classes),
|
155
156
|
data_maps: prepare_stimulus_option(options, :data_maps)
|
156
157
|
}
|
data/lib/vident/component.rb
CHANGED
@@ -17,6 +17,7 @@ module Vident
|
|
17
17
|
attribute :actions, default: [], delegates: false
|
18
18
|
attribute :targets, default: [], delegates: false
|
19
19
|
attribute :outlets, default: [], delegates: false
|
20
|
+
attribute :outlet_host, delegates: false
|
20
21
|
attribute :data_maps, default: [], delegates: false
|
21
22
|
attribute :named_classes, delegates: false
|
22
23
|
end
|
@@ -7,6 +7,7 @@ module Vident
|
|
7
7
|
actions: nil,
|
8
8
|
targets: nil,
|
9
9
|
outlets: nil,
|
10
|
+
outlet_host: nil,
|
10
11
|
named_classes: nil, # https://stimulus.hotwired.dev/reference/css-classes
|
11
12
|
data_maps: nil,
|
12
13
|
element_tag: nil,
|
@@ -23,6 +24,13 @@ module Vident
|
|
23
24
|
@named_classes = named_classes
|
24
25
|
@data_map_kvs = {}
|
25
26
|
@data_maps = data_maps
|
27
|
+
|
28
|
+
outlet_host.connect_outlet(self) if outlet_host.respond_to?(:connect_outlet)
|
29
|
+
end
|
30
|
+
|
31
|
+
def connect_outlet(outlet)
|
32
|
+
@outlets ||= []
|
33
|
+
@outlets << outlet
|
26
34
|
end
|
27
35
|
|
28
36
|
# The view component's helpers for setting stimulus data-* attributes on this component.
|
@@ -61,6 +69,20 @@ module Vident
|
|
61
69
|
build_target_data_attributes([target(name)])
|
62
70
|
end
|
63
71
|
|
72
|
+
def build_outlet_selector(outlet_selector)
|
73
|
+
prefix = @id ? "##{@id} " : ""
|
74
|
+
"#{prefix}[data-controller~=#{outlet_selector}]"
|
75
|
+
end
|
76
|
+
|
77
|
+
def outlet(css_selector: nil)
|
78
|
+
controller = implied_controller_name
|
79
|
+
if css_selector.nil?
|
80
|
+
[controller, build_outlet_selector(controller)]
|
81
|
+
else
|
82
|
+
[controller, css_selector]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
64
86
|
# Getter for a named classes list so can be used in view to set initial state on SSR
|
65
87
|
# Returns a String of classes that can be used in a `class` attribute.
|
66
88
|
def named_classes(*names)
|
@@ -87,6 +109,13 @@ module Vident
|
|
87
109
|
end
|
88
110
|
alias_method :with_action, :with_actions
|
89
111
|
|
112
|
+
# Return the HTML `data-` attribute for the given outlets
|
113
|
+
def with_outlets(*outlets)
|
114
|
+
attrs = build_outlet_data_attributes(outlets)
|
115
|
+
attrs.map { |dt, n| "data-#{dt}=\"#{n}\"" }.join(" ").html_safe
|
116
|
+
end
|
117
|
+
alias_method :with_outlet, :with_outlets
|
118
|
+
|
90
119
|
private
|
91
120
|
|
92
121
|
# An implicit Stimulus controller name is built from the implicit controller path
|
@@ -133,17 +162,29 @@ module Vident
|
|
133
162
|
|
134
163
|
def outlet_list
|
135
164
|
return {} unless @outlets&.size&.positive?
|
165
|
+
build_outlet_data_attributes(@outlets)
|
166
|
+
end
|
136
167
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
168
|
+
def parse_outlet(outlet_config)
|
169
|
+
if outlet_config.is_a?(String)
|
170
|
+
[outlet_config, build_outlet_selector(outlet_config)]
|
171
|
+
elsif outlet_config.is_a?(Symbol)
|
172
|
+
outlet_config = outlet_config.to_s.tr("_", "-")
|
173
|
+
[outlet_config, build_outlet_selector(outlet_config)]
|
174
|
+
elsif outlet_config.is_a?(Array)
|
175
|
+
outlet_config[..1]
|
176
|
+
elsif outlet_config.respond_to?(:stimulus_identifier) # Is a Component
|
177
|
+
[outlet_config.stimulus_identifier, build_outlet_selector(outlet_config.stimulus_identifier)]
|
178
|
+
elsif outlet_config.send(:implied_controller_name) # Is a RootComponent ?
|
179
|
+
[outlet_config.send(:implied_controller_name), build_outlet_selector(outlet_config.send(:implied_controller_name))]
|
180
|
+
else
|
181
|
+
raise ArgumentError, "Invalid outlet config: #{outlet_config}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def build_outlet_data_attributes(outlets)
|
186
|
+
outlets.each_with_object({}) do |outlet_config, obj|
|
187
|
+
identifier, css_selector = parse_outlet(outlet_config)
|
147
188
|
obj[:"#{implied_controller_name}-#{identifier}-outlet"] = css_selector
|
148
189
|
end
|
149
190
|
end
|
data/lib/vident/stable_id.rb
CHANGED
data/lib/vident/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vident
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|