Sha256: 516d040aebf0a94c0bc0c7a0687e641a142f4eec6de8fea89c34cdbd5734a7eb

Contents?: true

Size: 829 Bytes

Versions: 14

Compression:

Stored size: 829 Bytes

Contents

module PrivatePub
  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)
      PrivatePub.publish_to(channel, data || capture(&block))
    end

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

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
private_pub_no_sig-0.0.1 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.8 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.7 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.6 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.5 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.4 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.3 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.2 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.1 lib/private_pub/view_helpers.rb
peritus_private_pub-1.0.0 lib/private_pub/view_helpers.rb
private_pub-1.0.3 lib/private_pub/view_helpers.rb
private_pub-1.0.2 lib/private_pub/view_helpers.rb
private_pub-1.0.1 lib/private_pub/view_helpers.rb
private_pub-1.0.0 lib/private_pub/view_helpers.rb