Skip to content

Commit 51a123f

Browse files
committed
tag => child_element helper rename. Bump beta2
1 parent 33d9259 commit 51a123f

18 files changed

Lines changed: 140 additions & 136 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [1.0.0.beta2] - 2026-04-16
10+
11+
### Breaking
12+
13+
- Renamed the `tag(...)` helper to `child_element(...)` (and the internal `Vident::TagHelper` module to `Vident::ChildElementHelper`). The old name shadowed Rails' own `tag(name, options)` positional API, which breaks Rails helpers like `hidden_field_tag` and `image_tag` when called inside vident components. Rename any `component.tag(...)` calls to `component.child_element(...)`.
14+
15+
### Fixed
16+
17+
- `stimulus_outlet` parser now accepts `(String, String)` arguments so string-keyed outlets produced by the DSL actually render.
18+
919
## [1.0.0.beta1] - 2026-04-16
1020

1121
### Fixed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ButtonComponent < Vident::ViewComponent::Base
9393
def call
9494
root_element do |component|
9595
# Wire up targets etc
96-
component.tag(:span, stimulus_target: :status) do
96+
component.child_element(:span, stimulus_target: :status) do
9797
@text
9898
end
9999
end
@@ -483,13 +483,13 @@ or you can use tag helpers to generate HTML with Stimulus attributes:
483483
<% end %>
484484
<%= content_tag(:span, class: "...", data: {**greeter.stimulus_target(:output)}) %>
485485
486-
<%# OR use the vident tag helper %>
486+
<%# OR use the vident child_element helper %>
487487
488-
<%= greeter.tag(:input, stimulus_target: :name, type: "text", class: "...") %>
489-
<%= greeter.tag(:button, stimulus_action: [:click, :greet], class: "...") do %>
488+
<%= greeter.child_element(:input, stimulus_target: :name, type: "text", class: "...") %>
489+
<%= greeter.child_element(:button, stimulus_action: [:click, :greet], class: "...") do %>
490490
<%= @cta %>
491491
<% end %>
492-
<%= greeter.tag(:span, stimulus_target: :output, class: "...") %>
492+
<%= greeter.child_element(:span, stimulus_target: :output, class: "...") %>
493493
```
494494

495495
or in your Phlex templates:
@@ -498,7 +498,7 @@ or in your Phlex templates:
498498
root_element do |greeter|
499499
input(type: "text", data: {**greeter.stimulus_target(:name)}, class: %(...))
500500
trigger_or_default(greeter)
501-
greeter.tag(:span, stimulus_target: :output, class: "ml-4 #{greeter.class_list_for_stimulus_classes(:pre_click)}") do
501+
greeter.child_element(:span, stimulus_target: :output, class: "ml-4 #{greeter.class_list_for_stimulus_classes(:pre_click)}") do
502502
plain %( ... )
503503
end
504504
end

context/1_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def view_template
288288
root do |component|
289289
div(data: component.stimulus_target(:name).to_h) { "Content" }
290290
button(data: {**component.stimulus_actions(:click)}) { "Click" }
291-
component.tag(:span, stimulus_target: :output, class: "ml-4")
291+
component.child_element(:span, stimulus_target: :output, class: "ml-4")
292292
end
293293
end
294294
```

context/5_examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ end
6060
<%= form.label :advanced_mode, "Show advanced options" %>
6161
</div>
6262
63-
<%= component.tag(stimulus_targets: [:advanced_section]) do %>
63+
<%= component.child_element(stimulus_targets: [:advanced_section]) do %>
6464
class="<%= @show_advanced ? 'block' : 'hidden' %> p-4 bg-gray-50 rounded mb-4">
6565
<!-- Advanced fields -->
6666
<%= form.label :preferences, class: "block text-sm font-medium text-gray-700" %>

lib/vident.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
require "vident/stimulus_attributes"
3939
require "vident/stimulus_data_attribute_builder"
4040

41-
require "vident/tag_helper"
41+
require "vident/child_element_helper"
4242
require "vident/stable_id"
4343
require "vident/class_list_builder"
4444

lib/vident/child_element_helper.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
module Vident
4+
module ChildElementHelper
5+
def child_element(
6+
tag_name,
7+
stimulus_controllers: nil,
8+
stimulus_targets: nil,
9+
stimulus_actions: nil,
10+
stimulus_outlets: nil,
11+
stimulus_values: nil,
12+
stimulus_classes: nil,
13+
stimulus_controller: nil,
14+
stimulus_target: nil,
15+
stimulus_action: nil,
16+
stimulus_outlet: nil,
17+
stimulus_value: nil,
18+
stimulus_class: nil,
19+
**options,
20+
&block
21+
)
22+
child_element_attribute_must_be_collection!(stimulus_controllers, "stimulus_controllers")
23+
child_element_attribute_must_be_collection!(stimulus_targets, "stimulus_targets")
24+
child_element_attribute_must_be_collection!(stimulus_actions, "stimulus_actions")
25+
child_element_attribute_must_be_collection!(stimulus_outlets, "stimulus_outlets")
26+
child_element_attribute_must_be_collection!(stimulus_values, "stimulus_values")
27+
child_element_attribute_must_be_collection!(stimulus_classes, "stimulus_classes")
28+
29+
stimulus_controllers_collection = send(:stimulus_controllers, *child_element_wrap_single_stimulus_attribute(stimulus_controllers, stimulus_controller))
30+
stimulus_targets_collection = send(:stimulus_targets, *child_element_wrap_single_stimulus_attribute(stimulus_targets, stimulus_target))
31+
stimulus_actions_collection = send(:stimulus_actions, *child_element_wrap_single_stimulus_attribute(stimulus_actions, stimulus_action))
32+
stimulus_outlets_collection = send(:stimulus_outlets, *child_element_wrap_single_stimulus_attribute(stimulus_outlets, stimulus_outlet))
33+
stimulus_values_collection = send(:stimulus_values, stimulus_values || stimulus_value)
34+
stimulus_classes_collection = send(:stimulus_classes, stimulus_classes || stimulus_class)
35+
36+
stimulus_data_attributes = StimulusDataAttributeBuilder.new(
37+
controllers: stimulus_controllers_collection,
38+
actions: stimulus_actions_collection,
39+
targets: stimulus_targets_collection,
40+
outlets: stimulus_outlets_collection,
41+
values: stimulus_values_collection,
42+
classes: stimulus_classes_collection
43+
).build
44+
generate_child_element(tag_name, stimulus_data_attributes, options, &block)
45+
end
46+
47+
private
48+
49+
def child_element_attribute_must_be_collection!(collection, name)
50+
return unless collection
51+
raise ArgumentError, "'#{name}:' must be an enumerable. Did you mean '#{name.to_s.singularize}:'?" unless collection.is_a?(Enumerable)
52+
end
53+
54+
def child_element_wrap_single_stimulus_attribute(plural, singular)
55+
return plural if plural
56+
singular.nil? ? nil : [singular]
57+
end
58+
59+
def generate_child_element(tag_name, stimulus_data_attributes, options, &block)
60+
raise NoMethodError, "Not implemented"
61+
end
62+
end
63+
end

lib/vident/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def prop_names
2727
include ComponentClassLists
2828
include ComponentAttributeResolver
2929

30-
include TagHelper
30+
include ChildElementHelper
3131
include Tailwind
3232
include StimulusHelper
3333

lib/vident/phlex/html.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def check_valid_html_tag!(tag_name)
5151
end
5252
end
5353

54-
def generate_tag(tag_type, stimulus_data_attributes, options, &block)
54+
def generate_child_element(tag_type, stimulus_data_attributes, options, &block)
5555
options[:data] ||= {}
5656
options[:data].merge!(stimulus_data_attributes)
5757
check_valid_html_tag!(tag_type)

lib/vident/tag_helper.rb

Lines changed: 0 additions & 65 deletions
This file was deleted.

lib/vident/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Vident
4-
VERSION = "1.0.0.beta1"
4+
VERSION = "1.0.0.beta2"
55

66
# Shared version for all vident gems
77
def self.version

0 commit comments

Comments
 (0)