Created
January 20, 2010 11:52
-
-
Save mikezter/281794 to your computer and use it in GitHub Desktop.
Add Template Identification HTML Comments to ERB output in Rails
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
# Add Template Identification HTML Comments to ERB output | |
module ::ActionView | |
module TemplateHandlers | |
class ERB < TemplateHandler | |
include Compilable | |
cattr_accessor :erb_trim_mode | |
self.erb_trim_mode = '-' | |
def compile(template) | |
buf = <<-HTML | |
<% unless request and request.xhr? %> | |
<% __in_erb_template=true %>\n | |
<!-- // BEGIN #{ template } -->\n | |
<% end %> | |
#{ template.source }\n | |
<% unless request and request.xhr? %> | |
<!-- // END #{ template } -->\n | |
<% end %> | |
HTML | |
src = ::ERB.new(buf, nil, erb_trim_mode, '@output_buffer').src | |
RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment