Module: Pgbus::Streams::Renderer

Defined in:
lib/pgbus/streams/renderer.rb

Overview

Turns a renderable into a complete <turbo-stream> action tag, ready to hand to Stream#broadcast. This centralises the off-request render + tag-building that every consumer would otherwise stitch together by hand (the #1 footgun in server-driven UI: rendering a component outside a request without a usable view context).

pgbus deliberately has no hard dependency on turbo-rails, ActionView, or Phlex, so this builder is self-contained and matches Turbo's wire format directly. The browser's Turbo runtime consumes the tag; the exact string is the contract, not any particular Ruby library.

Renderable resolution (first match wins):

- String              → used verbatim (already-rendered markup)
- responds to :call   → Phlex::HTML#call (the issue's example shape)
- responds to :render_in → ViewComponent / phlex-rails
(`render_in(view_context)`; a nil context is passed because
off-request there is no controller — components that need URL
helpers should be rendered by the app and the string passed in)
- else                → to_s

Tag format mirrors Turbo::Streams::TagBuilder:

- content actions wrap the markup in a <template>
- content-less actions (remove) emit no <template>

Constant Summary collapse

CONTENTLESS_ACTIONS =

Turbo stream actions that carry no content (no