module PageletRails::Concerns::ResponseWrapper

Public Instance Methods

process_action(*args) click to toggle source
Calls superclass method
# File lib/pagelet_rails/concerns/response_wrapper.rb, line 4
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}', #{trigger_change.to_json.html_safe});"
        )

        self.response_body = [html]
      end
    end
  end
end