How to wrap partial with HTML comments?

I’d like to wrap all partial calls with “begin” and “end” HTML comments. This would allow for ‘breadcrumbs’ to help debugging/understanding of the built code. Any ideas on how to proceed?

Am I correct that partial is in the domain of Padrino? (I found partial defined in Padrino::Helpers::RenderHelpers.)

Could this be done cleanly via an extension? Or would there be some monkey-patching required to override/alias methods?

Any pointers or leads would be appreciated. Thanks!

Yes, you could do it in an extension (or in your helpers block in config.rb). Just define a partial method that looks something like this (guessing):

def partial(template, options)
    "<!-- begin #{template} -->\n#{super}\n<!-- end #{template} ->\n"
end

Thanks for the tip, @bhollis. I should have messed around with this a bit more before posting my question. I had a feeling it would be something like that, though I couldn’t do a strict super call because partial is not a class method, so I had nothing to subclass. (I think I described that accurately; it’s been a while since I had to dive this deep into Ruby.)

I ended up monkeypatching it via alias_method in lib/padrino_helpers.rb like so:

module Padrino
  module Helpers
    module RenderHelpers
      alias_method :orig_partial, :partial

      # redefine Padrino's 'partial' method (defined in render_helpers.rb) to 
      # wrap the partial in comments, thereby aiding integrators in 
      # understanding source code structure.
      # 
      # see http://forum.middlemanapp.com/t/how-to-wrap-partial-with-html-comments/1184/
      def partial(template, options={})
        [
          "<!-- BEGIN PARTIAL: #{template} -->",
          orig_partial(template, options),
          "<!-- END PARTIAL: #{template} -->"
        ].join("\n")
      end
  
    end
  end
end