Sha256: 243022585ff3066af12d78eb5cc0f972ac2630da4a26426ec3f5dd462846c6f4

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

module Skylight
  module Probes
    module ActionView
      class Probe
        def install
          # Rails 3.0 didn't have ActionView::TemplateRenderer, but it also
          # didn't have the bug that this probe is trying to fix. In Rails
          # 3.1, a templating engine refactor moved the layout rendering out
          # of the existing instrumentation, making any other events that
          # happen inside of the layout appear to happen directly inside the
          # parent (usually the controller).
          return if [ActionPack::VERSION::MAJOR, ActionPack::VERSION::MINOR] == [3, 0]

          ::ActionView::TemplateRenderer.class_eval do
            alias render_with_layout_without_sk render_with_layout

            def render_with_layout(path, locals, *args, &block) #:nodoc:
              layout = nil

              if path
                if ::ActionView.respond_to?(:gem_version) && ::ActionView.gem_version >= Gem::Version.new('5.x')
                  layout = find_layout(path, locals.keys, [formats.first])
                else
                  layout = find_layout(path, locals.keys)
                end
              end

              if layout
                instrument(:template, :identifier => layout.identifier) do
                  render_with_layout_without_sk(path, locals, *args, &block)
                end
              else
                render_with_layout_without_sk(path, locals, *args, &block)
              end
            end
          end
        end
      end
    end

    register("ActionView::TemplateRenderer", "action_view", ActionView::Probe.new)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
skylight-1.6.1 lib/skylight/probes/action_view.rb
skylight-1.6.0 lib/skylight/probes/action_view.rb