module Simplepub::ViewHelpers

Public Instance Methods

publish_to(channel, data = nil, &block) click to toggle source

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.

# File lib/simplepub/view_helpers.rb, line 8
def publish_to(channel, data = nil, &block)
  Simplepub.publish_to(channel, data || capture(&block))
end
subscribe_to(channel) click to toggle source

Subscribe the client to the given channel. This generates some JavaScript calling Simplepub.sign with the subscription options.

# File lib/simplepub/view_helpers.rb, line 15
def subscribe_to(channel)
  subscription = Simplepub.subscription(:channel => channel)
  content_tag "script", :type => "text/javascript" do
    raw("Simplepub.sign(#{subscription.to_json});")
  end
end