vident 0.11.0 → 0.12.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: ea398d33c180c2198ac689bd70d6f830dc625f9e70fd17bd94cb1acbaa7ec690
4
- data.tar.gz: 86b1e7379929fbbe3e5b83b9356debfa18490a9cca60599a1a7ecbd9537d97f7
3
+ metadata.gz: 503019b8aac7501339acff5c350afbca9abb55599a696f348321554da15183c0
4
+ data.tar.gz: 175ffd2794c1b7c81bf879a8bb3c9f65c42fa16cc92748be77df255c0b5fdcff
5
5
  SHA512:
6
- metadata.gz: 3e36f069043b62f9d300993e7be4d2cc8666aac6f782ee4ba04fd5efeaffe9ebd28ace5dbfd1022f90f515b253b9778d1123e516606fc20255b0d1bcb5a7bfe5
7
- data.tar.gz: abf930b3b049e617544a8fe274b0c7deac1ad4f8226642d88fe120246fa0935b90cbcd3206480604290e2f2b9ff540dbf234ab72df8fb4051d8b6838cbecbc11
6
+ metadata.gz: 0c76ae38a7c66032e99b130e21d67ba52f6c9fc946e3476fc945b682e5916ad406f90c12e0db2ab189ddf961e8c4f1a6e2cd64fc7e79bd6464ea5ccb1387e0de
7
+ data.tar.gz: f25903b4f38418a6752f33190713f0d8c9b3f5c2e251fb83476a35b2894df4dc848a3e104c13cf1d10ad448e774f924194020781f23b2c6d9732b061e0351e34
data/CHANGELOG.md CHANGED
@@ -15,6 +15,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
15
15
  ### Fixed
16
16
 
17
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
+
18
28
  ## [0.11.0] - 2024-02-21
19
29
 
20
30
  ### Added
@@ -69,10 +69,15 @@ module Vident
69
69
  build_target_data_attributes([target(name)])
70
70
  end
71
71
 
72
+ def build_outlet_selector(outlet_selector)
73
+ prefix = @id ? "##{@id} " : ""
74
+ "#{prefix}[data-controller~=#{outlet_selector}]"
75
+ end
76
+
72
77
  def outlet(css_selector: nil)
73
78
  controller = implied_controller_name
74
79
  if css_selector.nil?
75
- [controller, "[data-controller~=#{controller}]"]
80
+ [controller, build_outlet_selector(controller)]
76
81
  else
77
82
  [controller, css_selector]
78
83
  end
@@ -104,6 +109,13 @@ module Vident
104
109
  end
105
110
  alias_method :with_action, :with_actions
106
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
+
107
119
  private
108
120
 
109
121
  # An implicit Stimulus controller name is built from the implicit controller path
@@ -150,19 +162,29 @@ module Vident
150
162
 
151
163
  def outlet_list
152
164
  return {} unless @outlets&.size&.positive?
165
+ build_outlet_data_attributes(@outlets)
166
+ end
167
+
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
153
184
 
154
- @outlets.each_with_object({}) do |outlet_config, obj|
155
- identifier, css_selector = if outlet_config.is_a?(String)
156
- [outlet_config, "[data-controller~=#{outlet_config}]"]
157
- elsif outlet_config.is_a?(Array)
158
- outlet_config[..1]
159
- elsif outlet_config.respond_to?(:stimulus_identifier) # Is a Component
160
- [outlet_config.stimulus_identifier, "[data-controller~=#{outlet_config.stimulus_identifier}]"]
161
- elsif outlet_config.send(:implied_controller_name) # Is a RootComponent ?
162
- [outlet_config.send(:implied_controller_name), "[data-controller~=#{outlet_config.send(:implied_controller_name)}]"]
163
- else
164
- raise ArgumentError, "Invalid outlet config: #{outlet_config}"
165
- end
185
+ def build_outlet_data_attributes(outlets)
186
+ outlets.each_with_object({}) do |outlet_config, obj|
187
+ identifier, css_selector = parse_outlet(outlet_config)
166
188
  obj[:"#{implied_controller_name}-#{identifier}-outlet"] = css_selector
167
189
  end
168
190
  end
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "random/formatter"
3
+ begin
4
+ # Introduced in Ruby 3.1
5
+ require "random/formatter"
6
+ rescue LoadError
7
+ # to support Ruby 3.0
8
+ require "securerandom"
9
+ end
4
10
 
5
11
  module Vident
6
12
  class StableId
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vident
4
- VERSION = "0.11.0"
4
+ VERSION = "0.12.0"
5
5
  end
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.11.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-21 00:00:00.000000000 Z
11
+ date: 2024-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties