Class: Presently::PresenterView
- Inherits:
-
Live::View
- Object
- Live::View
- Presently::PresenterView
- Defined in:
- lib/presently/presenter_view.rb
Overview
The presenter-facing view with notes, timing, and slide previews.
Shows the current slide, next slide preview, presenter notes, timing controls, and pacing indicators. Updates the timing display every second via a background task.
Instance Method Summary collapse
-
#bind(page) ⇒ Object
Bind this view to a page and start the timing update loop.
-
#close ⇒ Object
Close this view and stop the timing update loop.
-
#format_duration(seconds) ⇒ Object
Format a duration in seconds as ‘M:SS`.
-
#handle(event) ⇒ Object
Handle an event from the client.
-
#initialize(id = Live::Element.unique_id, data = {}, controller: nil) ⇒ PresenterView
constructor
Initialize a new presenter view.
-
#render(builder) ⇒ Object
Render the full presenter view.
-
#render_timing(builder, slide) ⇒ Object
Render the timing bar with controls, elapsed/remaining time, and pacing.
-
#slide_changed! ⇒ Object
Called by the controller when the slide changes.
-
#update_timing! ⇒ Object
Push an update to just the timing section.
Constructor Details
#initialize(id = Live::Element.unique_id, data = {}, controller: nil) ⇒ PresenterView
Initialize a new presenter view.
19 20 21 22 23 |
# File 'lib/presently/presenter_view.rb', line 19 def initialize(id = Live::Element.unique_id, data = {}, controller: nil) super(id, data) @controller = controller @clock_task = nil end |
Instance Method Details
#bind(page) ⇒ Object
Bind this view to a page and start the timing update loop.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/presently/presenter_view.rb', line 27 def bind(page) super @controller.add_listener(self) # Update only the timing section every second. @clock_task = Async do while true update_timing! sleep 1 end end end |
#close ⇒ Object
Close this view and stop the timing update loop.
41 42 43 44 45 |
# File 'lib/presently/presenter_view.rb', line 41 def close @clock_task&.stop @controller.remove_listener(self) super end |
#format_duration(seconds) ⇒ Object
Format a duration in seconds as ‘M:SS`.
153 154 155 156 157 158 |
# File 'lib/presently/presenter_view.rb', line 153 def format_duration(seconds) seconds = seconds.to_i minutes = seconds / 60 secs = seconds % 60 format("%d:%02d", minutes, secs) end |
#handle(event) ⇒ Object
Handle an event from the client.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/presently/presenter_view.rb', line 61 def handle(event) action = event.dig(:detail, :action) case action when "next" @controller.advance! when "previous" @controller.retreat! when "pause" if !@controller.clock.started? @controller.clock.start! elsif @controller.clock.paused? @controller.clock.resume! else @controller.clock.pause! end @controller.save_state! when "reset" @controller.reset_timer! when "reload" @controller.reload! when "jump" if index = event.dig(:detail, :index) @controller.go_to(index.to_i) end end end |
#render(builder) ⇒ Object
Render the full presenter view.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/presently/presenter_view.rb', line 162 def render(builder) = @controller. = @controller. builder.tag(:div, class: "presenter") do # Controls bar builder.tag(:div, class: "controls") do builder.tag(:button, onClick: forward_event(action: "previous") ) do builder.text("← Previous") end builder.tag(:span, class: "slide-info") do builder.text("Slide #{@controller.current_index + 1} of #{@controller.}") end builder.tag(:button, onClick: forward_event(action: "next") ) do builder.text("Next →") end # Jump-to dropdown for marked slides markers = [] @controller..each_with_index do |s, i| if s.marker markers << [i, s.marker] end end unless markers.empty? builder.tag(:select, class: "jump-to", onChange: "live.forwardEvent(#{JSON.dump(@id)}, event, {action: 'jump', index: parseInt(this.value)}); this.value = '';" ) do builder.tag(:option, value: "", disabled: true, selected: true) do builder.text("Jump to…") end markers.each do |index, label| builder.tag(:option, value: index) do builder.text(label) end end end end builder.tag(:button, onClick: forward_event(action: "reload"), class: "reload" ) do builder.text("↻ Reload") end end # Slide previews builder.tag(:div, class: "previews") do # Current slide builder.tag(:div, class: "preview current-preview") do builder.tag(:h3){builder.text("Current")} builder.tag(:div, class: "preview-frame") do if renderer = SlideView.new(css_class: "slide preview-slide", controller: @controller) renderer.(builder, ) end end end # Next slide builder.tag(:div, class: "preview next-preview") do builder.tag(:h3){builder.text("Next")} builder.tag(:div, class: "preview-frame") do if renderer = SlideView.new(css_class: "slide preview-slide", controller: @controller) renderer.(builder, ) else builder.tag(:div, class: "no-slide") do builder.text("End of presentation") end end end end end # Timing render_timing(builder, ) # Presenter notes builder.tag(:div, class: "notes") do builder.tag(:h3){builder.text("Notes")} builder.tag(:div, class: "notes-content") do if &.notes builder.raw(.notes) else builder.tag(:p, class: "no-notes"){builder.text("No presenter notes for this slide.")} end end end end end |
#render_timing(builder, slide) ⇒ Object
Render the timing bar with controls, elapsed/remaining time, and pacing.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/presently/presenter_view.rb', line 92 def render_timing(builder, ) progress = (@controller. * 100).round(1) builder.tag(:div, class: "timing", style: "--slide-progress: #{progress}%") do pacing = @controller.pacing pacing_class = case pacing when :behind then "behind" when :ahead then "ahead" else "on-time" end builder.tag(:div, class: "timing-info #{pacing_class}") do builder.tag(:button, class: "pause-button", onClick: forward_event(action: "pause") ) do label = if !@controller.clock.started? "▶ Start" elsif @controller.clock.paused? "▶ Resume" else "⏸ Pause" end builder.text(label) end builder.tag(:button, class: "pause-button", onClick: forward_event(action: "reset") ) do builder.text("↺ Reset") end builder.tag(:span, class: "elapsed") do builder.text("Elapsed: #{format_duration(@controller.clock.elapsed)}") end builder.tag(:span, class: "remaining") do builder.text("Remaining: #{format_duration(@controller.time_remaining)}") end builder.tag(:span, class: "pacing-indicator") do indicator = case pacing when :behind then "⏩ Speed up" when :ahead then "⏪ Slow down" else "✓ On time" end builder.text(indicator) end if builder.tag(:span, class: "slide-duration") do builder.text("Slide: #{format_duration(.duration)}") end end end end end |
#slide_changed! ⇒ Object
Called by the controller when the slide changes.
48 49 50 |
# File 'lib/presently/presenter_view.rb', line 48 def self.update! end |
#update_timing! ⇒ Object
Push an update to just the timing section.
53 54 55 56 57 |
# File 'lib/presently/presenter_view.rb', line 53 def update_timing! replace(".timing") do |builder| render_timing(builder, @controller.) end end |