Class: InertiaJb::Props
- Inherits:
-
Object
- Object
- InertiaJb::Props
- Defined in:
- lib/inertia_jb/props.rb
Overview
The result of rendering an *.inertia template: the props Hash plus the
template's virtual path.
It exists so that Controller#render_to_body can tell "this is a set of Inertia props" from "this is a response body" without inspecting formats or guessing, and so the Inertia component name can be derived from the template that actually rendered.
Instance Attribute Summary collapse
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#virtual_path ⇒ Object
readonly
Returns the value of attribute virtual_path.
Instance Method Summary collapse
-
#component(configuration) ⇒ Object
The Inertia component name for this page.
-
#initialize(virtual_path, props) ⇒ Props
constructor
A new instance of Props.
Constructor Details
#initialize(virtual_path, props) ⇒ Props
Returns a new instance of Props.
14 15 16 17 |
# File 'lib/inertia_jb/props.rb', line 14 def initialize(virtual_path, props) @virtual_path = virtual_path @props = props end |
Instance Attribute Details
#props ⇒ Object (readonly)
Returns the value of attribute props.
12 13 14 |
# File 'lib/inertia_jb/props.rb', line 12 def props @props end |
#virtual_path ⇒ Object (readonly)
Returns the value of attribute virtual_path.
12 13 14 |
# File 'lib/inertia_jb/props.rb', line 12 def virtual_path @virtual_path end |
Instance Method Details
#component(configuration) ⇒ Object
The Inertia component name for this page.
Derived from the rendered template rather than from
controller_path/action_name, so an explicit render :edit points at
the edit component instead of the acting create.
The virtual path is split into the same path:/action: pair inertia-rails
feeds its own resolver, and handed to config.component_path_resolver
unconditionally — a custom resolver (camelizing, prefixing, ...) owns the
result in every case, including a page template that sits at the root of a
view path (path: is then "", which the default resolver renders as
"/name").
31 32 33 34 35 |
# File 'lib/inertia_jb/props.rb', line 31 def component(configuration) prefix, _, name = virtual_path.rpartition("/") configuration.component_path_resolver(path: prefix, action: name) end |