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
35
36
37
38
39
|
# File 'lib/svelte_on_rails/view_helpers.rb', line 5
def svelte(component, props = {}, options: {}, wrapper_html: {}, **kw_props)
raise ArgumentError, "props must be a Hash, got #{props.class}" unless props.is_a?(Hash)
raise ArgumentError, "props must not have a options key" if props.key?(:options)
raise ArgumentError, "props must not have a wrapper_html key" if props.key?(:wrapper_html)
component_props = props.deep_merge(kw_props)
config = SvelteOnRails::Configuration.instance
caching = if !options[:cached].nil?
options[:cached]
elsif !config.configs[:use_caching].nil?
config.configs[:use_caching]
else
false
end
support = SvelteOnRails::Lib::ViewHelperSupport.new(component, component_props, wrapper_html, options, request, calling_view_dir, caching)
if support.ssr?
if config.watch_changes? && !config.build_status['passed']
sor_error_tag(support, wrapper_html, component_props, 'server-side-svelte-build-error', 'BUILD FAILED')
elsif caching
support.set_request_metrics(:from_cache)
support.render_cached(self) do
render_component(support, wrapper_html, component_props)
end
else
r = render_component(support, wrapper_html, component_props)
support.log_completed("Rendered #{'as empty element that will be mounted on the client side' unless support.ssr?}")
r
end
else
render_empty_tag(support, wrapper_html, component_props)
end
end
|