Class: InertiaRails::Renderer
- Inherits:
-
Object
- Object
- InertiaRails::Renderer
- Defined in:
- lib/inertia_rails/renderer.rb
Constant Summary collapse
- KEEP_PROP =
:keep
- DONT_KEEP_PROP =
:dont_keep
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
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.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/inertia_rails/renderer.rb', line 20 def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil) @controller = controller @configuration = controller.__send__(:inertia_configuration) @component = resolve_component(component) @request = request @response = response @render_method = render_method @props = props || controller.__send__(:inertia_view_assigns) @view_data = view_data || {} @deep_merge = !deep_merge.nil? ? deep_merge : configuration.deep_merge_shared_data end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
12 13 14 |
# File 'lib/inertia_rails/renderer.rb', line 12 def component @component end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
12 13 14 |
# File 'lib/inertia_rails/renderer.rb', line 12 def configuration @configuration end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
12 13 14 |
# File 'lib/inertia_rails/renderer.rb', line 12 def controller @controller end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
12 13 14 |
# File 'lib/inertia_rails/renderer.rb', line 12 def props @props end |
Instance Method Details
#render ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inertia_rails/renderer.rb', line 32 def render if @response.headers["Vary"].blank? @response.headers["Vary"] = 'X-Inertia' else @response.headers["Vary"] = "#{@response.headers["Vary"]}, X-Inertia" end if @request.headers['X-Inertia'] @response.set_header('X-Inertia', 'true') @render_method.call json: page, status: @response.status, content_type: Mime[:json] else return render_ssr if configuration.ssr_enabled rescue nil @render_method.call template: 'inertia', layout: layout, locals: view_data.merge(page: page) end end |