Class: InertiaBuilder::Renderer

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

Instance Method Summary collapse

Constructor Details

#initialize(view_context, props, component) ⇒ Renderer

Returns a new instance of Renderer.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/inertia_builder/renderer.rb', line 5

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



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inertia_builder/renderer.rb', line 17

def render
  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