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.
-
#editor_url_for(path, line = 1) ⇒ Object
Generate an editor URL for the given file path.
-
#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.
20 21 22 23 24 25 |
# File 'lib/presently/presenter_view.rb', line 20 def initialize(id = Live::Element.unique_id, data = {}, controller: nil) super(id, data) @controller = controller @clock_task = nil @preview_renderer = SlideRenderer.new(css_class: "slide preview-slide", templates: controller&.templates) end |
Instance Method Details
#bind(page) ⇒ Object
Bind this view to a page and start the timing update loop.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/presently/presenter_view.rb', line 29 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.
43 44 45 46 47 |
# File 'lib/presently/presenter_view.rb', line 43 def close @clock_task&.stop @controller.remove_listener(self) super end |
#editor_url_for(path, line = 1) ⇒ Object
Generate an editor URL for the given file path.
95 96 97 |
# File 'lib/presently/presenter_view.rb', line 95 def editor_url_for(path, line = 1) Editor.url_for(path, line) end |
#format_duration(seconds) ⇒ Object
Format a duration in seconds as ‘M:SS`.
179 180 181 182 183 184 |
# File 'lib/presently/presenter_view.rb', line 179 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.
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 88 89 |
# File 'lib/presently/presenter_view.rb', line 63 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.
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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/presently/presenter_view.rb', line 188 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.}") if builder.text(" · ") builder.tag(:code, class: "slide-path") do builder.text(File.basename(.path)) end if editor_url = editor_url_for(.path) builder.tag(:a, href: editor_url, class: "edit-link") do builder.text("✎") end end end 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", data: {live_id: @id} ) 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 @preview_renderer.render(builder, ) 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 @preview_renderer.render(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 = &.notes builder.raw(notes.to_html) 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.
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/presently/presenter_view.rb', line 102 def render_timing(builder, ) progress = (@controller. * 100).round(1) = @controller. 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 # Speaker display — only shown when front matter includes a `speaker` key. if (current_speaker = &.speaker) builder.tag(:span, class: "speaker-info") do builder.tag(:span, class: "speaker-label"){builder.text("🎤")} builder.text(" #{current_speaker}") # Show upcoming speaker only when they differ from the current one. if (next_speaker = &.speaker) && next_speaker != current_speaker builder.tag(:span, class: "next-speaker") do builder.text(" → #{next_speaker}") end end end end end end end |
#slide_changed! ⇒ Object
Called by the controller when the slide changes.
50 51 52 |
# File 'lib/presently/presenter_view.rb', line 50 def self.update! end |
#update_timing! ⇒ Object
Push an update to just the timing section.
55 56 57 58 59 |
# File 'lib/presently/presenter_view.rb', line 55 def update_timing! replace(".timing") do |builder| render_timing(builder, @controller.) end end |