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: nil, view_data: nil, deep_merge: nil) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Constructor Details
#initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/inertia_rails/renderer.rb', line 9 def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil) @component = component.is_a?(TrueClass) ? "#{controller.controller_path}/#{controller.action_name}" : component @controller = controller @request = request @response = response @render_method = render_method @props = props ? props.with_indifferent_access : controller.inertia_view_assigns.with_indifferent_access @view_data = view_data || {} @deep_merge = !deep_merge.nil? ? deep_merge : InertiaRails.deep_merge_shared_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
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/inertia_rails/renderer.rb', line 20 def render 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 return render_ssr if ::InertiaRails.ssr_enabled? rescue nil @render_method.call template: 'inertia', layout: layout, locals: (view_data).merge({page: page}) end end |