Sha256: 4072cdced9207ddd4119dc1decb10cc5c2bf2351469267512a6b649607194ff7

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require "cable_ready"
require "parser/current"

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

    attr_reader :resource

    def initialize(resource:)
      @resource = resource
    end

    def broadcast
      resource.cubicle_element_ids.to_a.each do |element_id|
        /cubicle-(?<block_key>.+)/ =~ element_id
        block_store_item = Cubism.store[block_key]

        next if block_store_item.blank?

        block_source = Cubism.store[block_store_item.block_location]
        erubi = ActionView::Template::Handlers::ERB::Erubi.new(block_source)
        ast = Parser::CurrentRuby.parse erubi.src

        # html = ApplicationController.render(inline: block_source, locals: {current_user: block_store_item.user, "@project": block_store_item.resource, users: resource.present_users_for_element_id(element_id)})

        # binding.pry

        # context = ActionView::Base.with_view_paths(ActionController::Base.view_paths)
        # erubi = ActionView::Template::Handlers::ERB::Erubi.new(File.read(filename), filename: filename)
        # context = ApplicationController.new.view_context

        # filename, lineno = block_store_item.block_location.split

        # binding.pry

        # block = Cubism.store[block_key].block
        # view_context = Cubism.store[block_key].context
        # html = view_context.capture(resource.present_users_for_element_id(element_id), &block)

        cable_ready[element_id].inner_html(
          selector: "cubicle-element##{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']",
          html: "#{resource.present_users_for_element_id(element_id).map(&:id)}" 
        ).broadcast
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cubism-0.1.0.pre10 lib/cubism/broadcaster.rb~