Class: InertiaRails::Renderer
- Inherits:
-
Object
- Object
- InertiaRails::Renderer
- Defined in:
- lib/inertia_rails/renderer.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#view_data ⇒ Object
readonly
Returns the value of attribute view_data.
Instance Method Summary collapse
-
#initialize(component, controller, request, response, render_method, props:, view_data:) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Constructor Details
#initialize(component, controller, request, response, render_method, props:, view_data:) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 14 15 16 17 |
# File 'lib/inertia_rails/renderer.rb', line 9 def initialize(component, controller, request, response, render_method, props:, view_data:) @component = component @controller = controller @request = request @response = response @render_method = render_method @props = props || {} @view_data = view_data || {} end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
7 8 9 |
# File 'lib/inertia_rails/renderer.rb', line 7 def component @component end |
#view_data ⇒ Object (readonly)
Returns the value of attribute view_data.
7 8 9 |
# File 'lib/inertia_rails/renderer.rb', line 7 def view_data @view_data end |
Instance Method Details
#render ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/inertia_rails/renderer.rb', line 19 def render return render_ssr if ::InertiaRails.ssr_enabled? if @request.headers['X-Inertia'] @response.set_header('Vary', 'Accept') @response.set_header('X-Inertia', 'true') @render_method.call json: page, status: @response.status, content_type: Mime[:json] else @render_method.call template: 'inertia', layout: ::InertiaRails.layout, locals: (view_data).merge({page: page}) end end |