Sha256: feec7ae5e4ddc973dbf7b9d52a94523cac285ab843c3208b329339b77ad80d02

Contents?: true

Size: 839 Bytes

Versions: 2

Compression:

Stored size: 839 Bytes

Contents

module CisRailsChat
  module ViewHelpers
    # Publish the given data or block to the client by sending
    # a Net::HTTP POST request to the Faye server. If a block
    # or string is passed in, it is evaluated as JavaScript
    # on the client. Otherwise it will be converted to JSON
    # for use in a JavaScript callback.
    def publish_to(channel, data = nil, &block)
      CisRailsChat.publish_to(channel, data || capture(&block))
    end

    # Subscribe the client to the given channel. This generates
    # some JavaScript calling CisRailsChat.sign with the subscription
    # options.
    def subscribe_to(channel)
      subscription = CisRailsChat.subscription(:channel => channel)
      content_tag "script", :type => "text/javascript" do
        raw("CisRailsChat.sign(#{subscription.to_json});")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cis_rails_chat-1.0.3 lib/cis_rails_chat/view_helpers.rb
cis_rails_chat-1.0.2 lib/cis_rails_chat/view_helpers.rb