Module: SolidObjects::TurboStreamRenderer
- Defined in:
- lib/solid_objects/turbo_stream_renderer.rb,
sig/generated/lib/solid_objects/turbo_stream_renderer.rbs
Constant Summary collapse
- INVALIDATION_MARKER =
"solid_objects_invalidation:"- INVALIDATION_PATTERN =
/<!--solid_objects_invalidation:([A-Za-z0-9_=-]+)-->/
Class Method Summary collapse
- .component_refresh(registration, instance_id, revision) ⇒ Object
- .invalidation(stream) ⇒ Object
- .observable(broadcast) ⇒ Object
- .observable_value(reference, name, value) ⇒ Object
Instance Method Summary collapse
- #self?.component_refresh ⇒ String
- #self?.display_value ⇒ String
- #self?.invalidation ⇒ Hash[String, untyped]?
- #self?.morph_component_refresh ⇒ String
- #self?.observable ⇒ String
- #self?.observable_value ⇒ String
Class Method Details
.component_refresh(registration, instance_id, revision) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/solid_objects/turbo_stream_renderer.rb', line 42 def component_refresh(registration, instance_id, revision) return morph_component_refresh(registration, instance_id, revision) if registration.morph? target = registration.dom_id source = ERB::Util.html_escape( registration.refresh_url(instance_id, revision) ) revision_value = "#{instance_id}:#{revision}" %(<turbo-stream action="replace" target="#{target}"><template><turbo-frame id="#{target}" src="#{source}" data-solid-objects-revision="#{revision_value}" data-solid-objects-refresh="replace"></turbo-frame></template></turbo-stream>) end |
.invalidation(stream) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/solid_objects/turbo_stream_renderer.rb', line 54 def invalidation(stream) encoded = stream[INVALIDATION_PATTERN, 1] return unless encoded payload = JSON.parse(Base64.urlsafe_decode64(encoded)) return unless payload["instance_id"].is_a?(Integer) return unless payload["revision"].is_a?(Integer) return unless payload["observable_name"].is_a?(String) payload rescue ArgumentError, JSON::ParserError nil end |
.observable(broadcast) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/solid_objects/turbo_stream_renderer.rb', line 14 def observable(broadcast) reference = Reference.new( actor_type: broadcast.instance.actor_type, actor_id: broadcast.instance.actor_id ) stream = observable_value( reference, broadcast.observable_name, broadcast.value ) = Base64.urlsafe_encode64( JSON.generate( "instance_id" => broadcast.instance_id, "revision" => broadcast..sequence, "observable_name" => broadcast.observable_name ) ) "#{stream}<!--#{INVALIDATION_MARKER}#{}-->" end |
.observable_value(reference, name, value) ⇒ Object
35 36 37 38 39 |
# File 'lib/solid_objects/turbo_stream_renderer.rb', line 35 def observable_value(reference, name, value) target = DomIdentity.observable(reference, name) content = ERB::Util.html_escape(display_value(value)) %(<turbo-stream action="replace" target="#{target}"><template><span id="#{target}">#{content}</span></template></turbo-stream>) end |
Instance Method Details
#self?.component_refresh ⇒ String
16 |
# File 'sig/generated/lib/solid_objects/turbo_stream_renderer.rbs', line 16
def self?.component_refresh: (ComponentRegistration, Integer, Integer) -> String
|
#self?.display_value ⇒ String
22 |
# File 'sig/generated/lib/solid_objects/turbo_stream_renderer.rbs', line 22
def self?.display_value: (untyped) -> String
|
#self?.invalidation ⇒ Hash[String, untyped]?
19 |
# File 'sig/generated/lib/solid_objects/turbo_stream_renderer.rbs', line 19
def self?.invalidation: (String) -> Hash[String, untyped]?
|
#self?.morph_component_refresh ⇒ String
25 |
# File 'sig/generated/lib/solid_objects/turbo_stream_renderer.rbs', line 25
def self?.morph_component_refresh: (ComponentRegistration, Integer, Integer) -> String
|
#self?.observable ⇒ String
10 |
# File 'sig/generated/lib/solid_objects/turbo_stream_renderer.rbs', line 10
def self?.observable: (Broadcast) -> String
|
#self?.observable_value ⇒ String
13 |
# File 'sig/generated/lib/solid_objects/turbo_stream_renderer.rbs', line 13
def self?.observable_value: (Reference, Symbol | String, untyped) -> String
|