Sha256: 880ff94616b3324587a0aacb39ba580c97b600dc94d64a1e627113f9615de872

Contents?: true

Size: 990 Bytes

Versions: 7

Compression:

Stored size: 990 Bytes

Contents

require "cable_ready"

module Cubism
  class Broadcaster
    include CableReady::Broadcaster
    include CableReady::StreamIdentifier

    attr_reader :resource

    def initialize(resource:)
      @resource = resource
    end

    def broadcast
      resource.cubicle_element_ids.to_a.each do |element_id|
        block_container = Cubism.block_store[element_id]

        next if block_container.blank?

        present_users = resource.present_users_for_element_id_and_scope(element_id, block_container.scope)

        block_source = block_container.block_source

        html = ApplicationController.render(inline: block_source.source, locals: {"#{block_source.variable_name}": present_users})

        selector = "cubicle-element#cubicle-#{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']"

        cable_ready[element_id].inner_html(
          selector: selector,
          html: html
        )
      end

      cable_ready.broadcast
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cubism-0.2.0 lib/cubism/broadcaster.rb
cubism-0.1.1 lib/cubism/broadcaster.rb
cubism-0.1.0 lib/cubism/broadcaster.rb
cubism-0.1.0.rc2 lib/cubism/broadcaster.rb
cubism-0.1.0.rc1 lib/cubism/broadcaster.rb
cubism-0.1.0.pre13 lib/cubism/broadcaster.rb
cubism-0.1.0.pre12 lib/cubism/broadcaster.rb