Module: UniversalRenderer::SSR::Helpers

Defined in:
lib/universal_renderer/ssr/helpers.rb

Instance Method Summary collapse

Instance Method Details

#sanitize_ssr(html) ⇒ Object



39
40
41
# File 'lib/universal_renderer/ssr/helpers.rb', line 39

def sanitize_ssr(html)
  sanitize(html, scrubber: Scrubber.new)
end

#ssr_bodyObject



22
23
24
25
26
27
28
29
30
# File 'lib/universal_renderer/ssr/helpers.rb', line 22

def ssr_body
  if ssr_streaming?
    Placeholders::BODY
  elsif @ssr && @ssr.body.present?
    sanitize_ssr(@ssr.body)
  else
    ""
  end
end

#ssr_headObject



8
9
10
11
12
13
14
15
16
# File 'lib/universal_renderer/ssr/helpers.rb', line 8

def ssr_head
  if ssr_streaming?
    Placeholders::HEAD
  elsif @ssr && @ssr.head.present?
    sanitize_ssr(@ssr.head)
  else
    ""
  end
end

#ssr_props(id: "ssr-props", props: nil) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/universal_renderer/ssr/helpers.rb', line 58

def ssr_props(id: "ssr-props", props: nil)
  (
    :script,
    ssr_props_json(props),
    { id: id, type: "application/json" },
    false
  )
end

#ssr_props_json(props = nil) ⇒ Object



48
49
50
51
# File 'lib/universal_renderer/ssr/helpers.rb', line 48

def ssr_props_json(props = nil)
  raw_props = props || @universal_renderer_props || {}
  ERB::Util.json_escape(raw_props.to_json)
end

#ssr_streaming?Boolean?

Determines if SSR streaming should be used for the current request. The decision is based solely on the ssr_streaming_preference class attribute set on the controller.

  • If ssr_streaming_preference is true, streaming is enabled.
  • If ssr_streaming_preference is false, streaming is disabled.
  • If ssr_streaming_preference is nil (not set), streaming is disabled.

Returns:

  • (Boolean, nil)

    The value of ssr_streaming_preference (true, false, or nil). In conditional contexts, nil will behave as false.



76
# File 'lib/universal_renderer/ssr/helpers.rb', line 76

delegate :ssr_streaming?, to: :controller