Class: InertiaJb::Renderer

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

Overview

Bridges a props Hash (built by a .html.inertia template) to the Inertia protocol via InertiaRails::Renderer.

Because the props are already a plain Ruby Hash, InertiaRails::Renderer can walk them natively: shared data is merged in, Procs and prop objects (optional/always/defer/scroll) are resolved, and partial reloads are filtered at any nesting depth.

Instance Method Summary collapse

Constructor Details

#initialize(view_context, props, component) ⇒ Renderer

Returns a new instance of Renderer.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/inertia_jb/renderer.rb', line 12

def initialize(view_context, props, component)
  @view_context = view_context
  @inertia_renderer = ::InertiaRails::Renderer.new(
    component,
    view_context.controller,
    view_context.request,
    view_context.response,
    view_context.controller.method(:render),
    props: props
  )
end

Instance Method Details

#renderObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/inertia_jb/renderer.rb', line 24

def render
  # `page` computes the full Inertia page hash (running PropsResolver)
  # without triggering a controller render, so we can return the body
  # ourselves from inside the template rendering pipeline.
  page = @inertia_renderer.send(:page)

  if @view_context.request.headers["X-Inertia"]
    page.to_json
  else
    @view_context.controller.render_to_string(
      template: "inertia",
      layout: false,
      locals: { page: page }
    )
  end
end