4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/render_turbo_stream/check_template.rb', line 4
def initialize(partial: nil, template: nil, available_instance_variables: nil, action: nil)
if !partial && !template
raise 'missing attribute partial xor template'
end
unless action
raise 'missing required attribute: action'
end
@action = action
@partial_path = partial
@template_path = template
@available_instance_variables = nil
prt = (partial ? partial : template).split('/')
if prt.length < 2
raise 'Partial or template path must always be specified with the controller path, for example «articles/partial_name».'
end
@controller_path = prt[0..-2].join('/')
@key = relative_path(partial: partial, template: template)
if production?
$render_turbo_stream_check_templates ||= {}
if $render_turbo_stream_check_templates[@key]
@result = $render_turbo_stream_check_templates[@key]
else
@result = { instance_variables: [] }
fetch_nested_partials(1, partial: @partial_path, template: @template_path)
$render_turbo_stream_check_templates[@key] ||= @result
end
else
@result = { instance_variables: [] }
fetch_nested_partials(1, partial: @partial_path, template: @template_path)
end
end
|