module BigpipeRails::Helper::InstanceMethods

Public Instance Methods

bigpipe(container, opts = {}, &block) click to toggle source

helper method to put Bigpipe on the page

# File lib/bigpipe_rails/helper.rb, line 7
def bigpipe(container, opts = {}, &block)
  @bigpipe_js = []
  @bigpipe_css = []
  opts[:append] ||= false
  opts[:container] = container
  self.bigpipes << [opts, block]
end
bigpipes() click to toggle source

accessor

# File lib/bigpipe_rails/helper.rb, line 15
def bigpipes
  @bigpipes ||= []
end
render_bigpipe() click to toggle source

render the collection

# File lib/bigpipe_rails/helper.rb, line 19
def render_bigpipe
  @bigpipes.each do |pipe|
    opts, block = pipe
    # we actually run the block here -
    # TODO: use em-synchrony and/or our own Fiber implementation
    opts[:content] = capture(&block)
    # TODO: we are re-escaping here for some reason - should be able to use javascript_tag
    # helper, need to see why it doesn't work
    data = %Q{
      <script type="text/javascript">
        <![CDATA[
          BigPipe.add_pagelet(#{opts.to_json});
        ]]>
      </script>
    }
    self.output_buffer.safe_concat(data)
  end
  ""
end