Class: InertiaJb::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_jb/handler.rb

Overview

ActionView template handler for *.html.inertia templates.

An .html.inertia template is jb-style Ruby: its last expression is a Hash of Inertia props. The handler evaluates that Hash and immediately throws it back to Controller#default_render, which hands it to inertia-rails' native renderer. The throw also aborts this implicit render (and the layout it was about to apply), so the handler emits no body of its own.

Class Method Summary collapse

Class Method Details

.call(template, source = nil) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/inertia_jb/handler.rb', line 12

def self.call(template, source = nil)
  source ||= template.source

  # `begin;#{source}` keeps the template's own line numbers aligned in
  # backtraces. The block evaluates to the template's last expression (the
  # props Hash), which we throw up to the controller to render.
  "throw(:__inertia_jb, begin;#{source}\nend)"
end