4
4
5
5
module InertiaRails
6
6
class Renderer
7
- attr_reader :component , :view_data , :configuration
7
+ attr_reader (
8
+ :component ,
9
+ :configuration ,
10
+ :controller ,
11
+ :props ,
12
+ :view_data ,
13
+ )
8
14
9
15
def initialize ( component , controller , request , response , render_method , props : nil , view_data : nil , deep_merge : nil )
10
16
@component = component . is_a? ( TrueClass ) ? "#{ controller . controller_path } /#{ controller . action_name } " : component
11
17
@controller = controller
12
- @configuration = controller . send ( :inertia_configuration )
18
+ @configuration = controller . __send__ ( :inertia_configuration )
13
19
@request = request
14
20
@response = response
15
21
@render_method = render_method
16
- @props = props ? props : controller . inertia_view_assigns
22
+ @props = props || controller . __send__ ( : inertia_view_assigns)
17
23
@view_data = view_data || { }
18
24
@deep_merge = !deep_merge . nil? ? deep_merge : configuration . deep_merge_shared_data
19
25
end
@@ -25,7 +31,7 @@ def render
25
31
@render_method . call json : page , status : @response . status , content_type : Mime [ :json ]
26
32
else
27
33
return render_ssr if configuration . ssr_enabled rescue nil
28
- @render_method . call template : 'inertia' , layout : layout , locals : ( view_data ) . merge ( { page : page } )
34
+ @render_method . call template : 'inertia' , layout : layout , locals : view_data . merge ( page : page )
29
35
end
30
36
end
31
37
@@ -43,13 +49,17 @@ def layout
43
49
configuration . layout
44
50
end
45
51
52
+ def shared_data
53
+ controller . __send__ ( :inertia_shared_data )
54
+ end
55
+
46
56
def computed_props
47
57
# Cast props to symbol keyed hash before merging so that we have a consistent data structure and
48
58
# avoid duplicate keys after merging.
49
59
#
50
60
# Functionally, this permits using either string or symbol keys in the controller. Since the results
51
61
# is cast to json, we should treat string/symbol keys as identical.
52
- _props = :: InertiaRails . shared_data ( @controller ) . deep_symbolize_keys . send ( prop_merge_method , @ props. deep_symbolize_keys ) . select do |key , prop |
62
+ _props = shared_data . deep_symbolize_keys . send ( prop_merge_method , props . deep_symbolize_keys ) . select do |key , prop |
53
63
if rendering_partial_component?
54
64
key . in? partial_keys
55
65
else
@@ -60,7 +70,7 @@ def computed_props
60
70
deep_transform_values (
61
71
_props ,
62
72
lambda do |prop |
63
- prop . respond_to? ( :call ) ? @ controller. instance_exec ( &prop ) : prop
73
+ prop . respond_to? ( :call ) ? controller . instance_exec ( &prop ) : prop
64
74
end
65
75
)
66
76
end
0 commit comments