Class: Monolith::ExceptionsController::SourceExtract

Inherits:
View
  • Object
show all
Defined in:
app/controllers/monolith/exceptions_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#extract=(value) ⇒ Object (writeonly)

Sets the attribute extract

Parameters:

  • the value to set the attribute extract to.



315
316
317
# File 'app/controllers/monolith/exceptions_controller.rb', line 315

def extract=(value)
  @extract = value
end

Instance Method Details

#view_templateObject



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'app/controllers/monolith/exceptions_controller.rb', line 317

def view_template
  return unless @extract

  turbo_frame_tag "source-view", class: "h-full overflow-y-auto block" do
    div(class: "min-h-full bg-gray-900") do
      # File header (sticky at top)
      div(class: "sticky top-0 bg-gray-800 text-gray-300 px-6 py-3 font-mono text-xs border-b border-gray-700 z-10") do
        span(class: "text-gray-500") { "📄 " }
        span(class: "text-green-400") { @extract[:file] }
      end

      # Code lines - text editor style
      div(class: "p-6") do
        div(class: "font-mono text-sm") do
          @extract[:lines].each do |line_data|
            div(
              id: "L#{line_data[:number]}",
              class: line_data[:highlighted] ? "bg-red-900/30 border-l-4 border-red-500" : ""
            ) do
              div(class: "flex") do
                # Line number (left side, text editor style)
                div(class: "px-4 py-1 text-right select-none text-gray-600 min-w-[4rem]") do
                  if line_data[:highlighted]
                    span(class: "text-red-400 font-bold") { line_data[:number].to_s }
                  else
                    plain line_data[:number].to_s
                  end
                end
                # Code content
                div(class: "px-4 py-1 flex-1 whitespace-pre") do
                  code(class: line_data[:highlighted] ? "text-red-300" : "text-gray-300") do
                    plain line_data[:content]
                  end
                end
              end
            end
          end
        end
      end

      # Auto-scroll to highlighted line on load
      if @extract[:line_number]
        script do
          raw safe("document.addEventListener('turbo:frame-load', function(e) { if (e.target.id === 'source-view') { setTimeout(() => { const el = document.getElementById('L#{@extract[:line_number]}'); if (el) { el.scrollIntoView({ block: 'center', behavior: 'smooth' }); } }, 50); } });")
        end
      end
    end
  end
end