Module: CubismHelper

Includes:
CableReady::StreamIdentifier
Defined in:
app/helpers/cubism_helper.rb

Instance Method Summary collapse

Instance Method Details

#cubicle_for(resource, user, scope: "", html_options: {}, appear_trigger: :connect, disappear_trigger: nil, trigger_root: nil, exclude_current_user: true, &block) ⇒ Object



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 'app/helpers/cubism_helper.rb', line 4

def cubicle_for(resource, user, scope: "", html_options: {}, appear_trigger: :connect, disappear_trigger: nil, trigger_root: nil, exclude_current_user: true, &block)
  block_location = block.source_location.join(":")
  block_source = Cubism::BlockSource.find_or_create(
    location: block_location,
    view_context: self
  )

  resource_gid = resource.to_gid.to_s

  block_container = Cubism::BlockContainer.new(
    block_location: block_location,
    block_source: block_source,
    resource_gid: resource_gid,
    user_gid: user.to_gid.to_s,
    scope: scope
  )

  digested_block_key = block_container.digest

  Cubism.block_store.fetch(digested_block_key, block_container)

  tag.cubicle_element(
    identifier: signed_stream_identifier(resource_gid),
    "appear-trigger": Array(appear_trigger).join(","),
    "disappear-trigger": disappear_trigger,
    "trigger-root": trigger_root,
    id: "cubicle-#{digested_block_key}",
    "exclude-current-user": exclude_current_user,
    **html_options
  )
end