Sha256: 3b30ed346a1818e1d82c25cf9ff4c892a28d914ec40f01444ce982bc09407858

Contents?: true

Size: 703 Bytes

Versions: 5

Compression:

Stored size: 703 Bytes

Contents

module PartiallyUseful
  module PartialRenderer
    def self.included(klass)
      klass.send :alias_method, :original_rails_render, :render
      klass.send :remove_method, :render
    end

    def render(context, options, block)
      if html_context?(context)
        msg = "rendering '#{options[:partial]}' with locals '#{(options[:locals] || {}).keys}'"
        "<!-- start #{msg}-->\n#{original_rails_render(context, options, block)}\n<!-- end #{msg}-->\n".html_safe
      else
        original_rails_render(context, options, block)
      end
    end

    private

    def html_context?(context)
      if context && context.request
        context.request.format.html?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
partially_useful-5.1.0 lib/partially_useful/partial_renderer.rb
partially_useful-5.0.0 lib/partially_useful/partial_renderer.rb
partially_useful-0.2.2 lib/partially_useful/partial_renderer.rb
partially_useful-0.2.1 lib/partially_useful/partial_renderer.rb
partially_useful-0.2.0 lib/partially_useful/partial_renderer.rb