You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document how to extend turbo_stream for custom actions (hotwired#555)
Closes [hotwired#554][]
The current `Turbo::Streams::TagBuilder` class supports the actions that
Turbo provides out of the box.
For applications that define [Custom Stream Actions][], this new support
aims to provide them with a mechanism to define Rails-side helpers.
For example, consider an `[action="highlight"]` custom stream. To build
those with first-party tooling, applications could add a [hook block][]
to their initializer:
```ruby
# config/initializers/turbo.rb
ActiveSupport.on_load :turbo_streams_tag_builder do
def highlight(target)
action :highlight, target
end
def highlight_all(targets)
action_all :highlight, targets
end
end
turbo_stream.highlight "my-element"
# => <turbo-stream action="highlight" target="my-element"><template></template></turbo-stream>
turbo_stream.highlight_all ".my-selector"
# => <turbo-stream action="highlight" targets=".my-selector"><template></template></turbo-stream>
```
[hotwired#554]: hotwired#554
[Custom Stream Actions]: https://turbo.hotwired.dev/handbook/streams#custom-actions
[hook block]: https://edgeapi.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html#method-i-on_load
0 commit comments