class DisplayView
The audience-facing display view that renders the current slide full-screen.
Connects to the class Presently::PresentationController as a listener and updates
whenever the slide changes. Pushes the current state on WebSocket reconnect.
Definitions
def initialize(id = Live::Element.unique_id, data = {}, controller: nil)
Initialize a new display view.
Signature
-
parameter
idString The unique element identifier.
-
parameter
dataHash The element data attributes.
-
parameter
controllerPresentationController | Nil The shared presentation controller.
Implementation
def initialize(id = Live::Element.unique_id, data = {}, controller: nil)
super(id, data)
@controller = controller
@slide_renderer = SlideRenderer.new(css_class: "slide current", templates: controller&.templates)
end
def bind(page)
Bind this view to a page and register as a listener. Immediately pushes the current state to the client.
Signature
-
parameter
pageLive::Page The page this view is bound to.
Implementation
def bind(page)
super
@controller.add_listener(self)
self.update!
end
def close
Close this view and unregister as a listener.
Implementation
def close
@controller.remove_listener(self)
super
end
def slide_changed!
Called by the controller when the slide changes.
Implementation
def slide_changed!
self.update!
end
def handle(event)
Handle an event from the client.
Signature
-
parameter
eventHash The event data with
:detailcontaining the action.
Implementation
def handle(event)
case event.dig(:detail, :action)
when "next"
@controller.advance!
when "previous"
@controller.retreat!
end
end
def render(builder)
Render the display view.
Signature
-
parameter
builderXRB::Builder The HTML builder.
Implementation
def render(builder)
slide = @controller.current_slide
return unless slide
builder.tag(:div, class: "display", data: {transition: slide.transition}) do
builder.tag(:div, class: "slide-container") do
@slide_renderer.render(builder, slide)
end
builder.tag(:div, class: "slide-counter") do
builder.text("#{@controller.current_index + 1} / #{@controller.slide_count}")
end
end
end