Skip to content

Instantly share code, notes, and snippets.

@mschuerig
Created June 8, 2012 06:41
Show Gist options
  • Save mschuerig/2893986 to your computer and use it in GitHub Desktop.
Save mschuerig/2893986 to your computer and use it in GitHub Desktop.
Rails initializer that adds comments to generated markup identifying which template it came from
unless Rails.env.production?
# Inspired by http://github.com/fcheung/tattler/blob/master/lib/tattler.rb
#
class ActionView::Template
def render_with_comment(*args, &block)
render_result = render_without_comment(*args, &block)
if mime_type.nil? || mime_type.in?([Mime::HTML, Mime::XML])
[
"<!-- STARTTEMPLATE: #{identifier} -->",
render_result,
"<!-- ENDTEMPLATE: #{identifier} -->"
].join("\n").html_safe
else
render_result
end
end
alias_method_chain :render, :comment
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment