Sha256: 908d0353b08969f8cfe5e00864302f975a0c08d81bbdbb6093326f6360602d03

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module PageletRails::Concerns::Placeholder
  extend ActiveSupport::Concern

  # This concern should be called after cache callback
  # #process_action method does not give such order
  # as it's called before callbacks
  def send_action *args
    render_remote_load
    if !performed?
      super
    end
  end

  def render_remote_load
    # puts 'render_remote_load'.blue
    render_remotely = pagelet_render_remotely?
    if render_remotely && pagelet_options.has_cache
      render_remotely = false
    end

    return unless render_remotely

    data = params.deep_dup
    data.permit!

    if pagelet_options.remote == :ssi
      path = url_for data.merge(
        only_path: true,
        original_pagelet_options: pagelet_encoded_original_options
      )
      render body: "<!--#include virtual=\"#{path}\" -->"
    else
      if pagelet_options.remote != :stream
        pagelet_options html: { 'data-pagelet-load' => 'true' }
      end

      default_view = '/layouts/pagelet_rails/loading_placeholder'
      view = pagelet_options.placeholder.try(:[], :view).presence || default_view

      render view
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pagelet_rails-0.2.2 lib/pagelet_rails/concerns/placeholder.rb
pagelet_rails-0.2.1 lib/pagelet_rails/concerns/placeholder.rb
pagelet_rails-0.2.0 lib/pagelet_rails/concerns/placeholder.rb
pagelet_rails-0.1.8 lib/pagelet_rails/concerns/placeholder.rb