Skip to content

Commit

Permalink
Do not automatically insert paloma hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kbparagua committed Apr 25, 2015
1 parent 6427134 commit 40c3ce8
Showing 1 changed file with 7 additions and 30 deletions.
37 changes: 7 additions & 30 deletions lib/paloma/action_controller_extension.rb
Expand Up @@ -12,7 +12,7 @@ def self.included base
prepend_view_path "#{Paloma.root}/app/views/"

before_filter :track_paloma_request
after_filter :append_paloma_hook, :if => :not_redirect?
helper_method :insert_paloma_hook
end
end

Expand Down Expand Up @@ -107,47 +107,24 @@ def track_paloma_request


#
# Before rendering html reponses,
# this is exectued to append Paloma's html hook to the response.
# Call in your view to insert Paloma's html hook.
#
# The html hook contains the javascript code that
# will execute the tracked Paloma requests.
#
def append_paloma_hook
def insert_paloma_hook
return true if self.paloma.has_no_request?

# Render the partial if it is present, otherwise do nothing.
begin
hook = view_context.render(
:partial => 'paloma/hook',
:locals => {:request => self.paloma.request})
rescue ActionView::MissingTemplate
return true
end

before_body_end_index = response_body[0].rindex('</body>')

# Append the hook after the body tag if it is present.
if before_body_end_index.present?
before_body = response_body[0][0, before_body_end_index].html_safe
after_body = response_body[0][before_body_end_index..-1].html_safe

response.body = before_body + hook + after_body
else
# If body tag is not present, append hook in the response body
response.body += hook
end
hook = view_context.render(
:partial => 'paloma/hook',
:locals => {:request => self.paloma.request})

self.paloma.clear_request
hook
end
end


def not_redirect?
self.status != 302
end


#
# Make sure not to execute paloma on the following response type
#
Expand Down

0 comments on commit 40c3ce8

Please sign in to comment.