Created
August 30, 2011 16:38
-
-
Save patmaddox/1181316 to your computer and use it in GitHub Desktop.
HTML comments to tell you what partial is rendering
This file contains hidden or 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
# Throw a comment in before and after every render call on html based templates | |
module ActionView # :nodoc: all | |
class Base | |
alias_method :render_file_without_comments, :render | |
attr_accessor :render_stack | |
def render(options = {}, local_assigns = {}, &block) | |
self.render_stack ||= [] | |
if options[:partial] | |
path = _pick_partial_template(options[:partial]) | |
elsif options[:file] | |
path = self.view_paths.find_template(options[:file], template_format) | |
end | |
self.render_stack.push(path) if path | |
without_comments = render_file_without_comments(options, local_assigns, &block) | |
parent_render_path = render_stack.size > 1 ? render_stack[render_stack.size - 2] : nil | |
if path | |
self.render_stack.pop | |
comment_string = "#{path}" | |
comment_string += " CALLED FROM #{parent_render_path}" if parent_render_path | |
end | |
return without_comments if template_format != :html || options[:without_comments] || self.render_stack.size == 0 || path.to_s[0, 8] == "layouts/" | |
"\n<!-- BEGIN #{comment_string} -->\n" + without_comments + "\n<!-- END #{comment_string} -->\n" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like it. Might be cool to put in a timing for the actual call to render. I've started being very judicious with my partials due to performance concerns.