Sha256: 9fe4ba4ac725e8c1a21af935ef8f803c5a798b064f0608a186c4364c1acf4a24

Contents?: true

Size: 890 Bytes

Versions: 6

Compression:

Stored size: 890 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

6 entries across 6 versions & 1 rubygems

Version Path
pagelet_rails-0.1.7 lib/pagelet_rails/concerns/response_wrapper.rb
pagelet_rails-0.1.6 lib/pagelet_rails/concerns/response_wrapper.rb
pagelet_rails-0.1.5 lib/pagelet_rails/concerns/response_wrapper.rb
pagelet_rails-0.1.4 lib/pagelet_rails/concerns/response_wrapper.rb
pagelet_rails-0.1.3 lib/pagelet_rails/concerns/response_wrapper.rb
pagelet_rails-0.1.2 lib/pagelet_rails/concerns/response_wrapper.rb