Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information