Created
June 8, 2012 06:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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