Sha256: 476389cc36fe33467cc166df845aec72358745c924bbec4bd3b03887ceaf1216

Contents?: true

Size: 889 Bytes

Versions: 2

Compression:

Stored size: 889 Bytes

Contents

module PageletRails::Concerns::ResponseWrapper
  extend ActiveSupport::Concern

  def process_action *args
    super.tap do
      if params[:target_container] &&
        action_has_layout? &&
        request.format.js? # wrap to js only if requested js

        response.content_type = 'text/javascript'

        html = self.response_body.reduce('') { |memo, body|
          memo << body
          memo
        }

        if html.match /^\s*</
          # the body could be javascript, make sure it's html before wrapping

          id = ActionController::Base.helpers.escape_javascript params[:target_container]
          js = ActionController::Base.helpers.escape_javascript html

          html = ActionController::Base.helpers.raw(
            "PageletRails.pageletArrived('#{id}', '#{js}');"
          )

          self.response_body = [html]
        end
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pagelet_rails-0.1.1 lib/pagelet_rails/concerns/response_wrapper.rb
pagelet_rails-0.1.0 lib/pagelet_rails/concerns/response_wrapper.rb