Sha256: 06754652dcfc96f1c51d407410797464f61b25b27d7b7e0db36617154fb89a7c

Contents?: true

Size: 1.51 KB

Versions: 6

Compression:

Stored size: 1.51 KB

Contents

require "#{File.dirname(__FILE__)}/log_note"

module Footnotes
  module Notes
    class PartialsNote < LogNote

      def initialize(controller)
        super
        @controller = controller
      end

      def row
        :edit
      end

      def title
        "Partials (#{partials.size})"
      end

      def content
        rows = partials.map do |filename|
          href = Footnotes::Filter.prefix(filename,1,1)
          name = filename.gsub(Rails.root.join("app/views/").to_s, '')
          [%{<a href="#{href}">#{name}</a>},"#{@partial_times[filename].sum}ms", @partial_counts[filename]]
        end
        mount_table(rows.unshift(%w(Partial Time Count)), :summary => "Partials for #{title}")
      end

      def self.load
        self.loaded = true unless loaded
      end

    protected
      #Generate a list of partials that were rendered, also build up render times and counts.
      #This is memoized so we can use its information in the title easily.
      def partials
        @partials ||= begin
          partials = []
          @partial_counts = {}
          @partial_times = {}
          Footnotes.view_subscriber.partials.each do |event|
            partial = event.payload[:identifier]
            @partial_times[partial] ||= []
            @partial_times[partial] << event.duration
            @partial_counts[partial] ||= 0
            @partial_counts[partial] += 1
            partials << partial unless partials.include?(partial)
          end
          partials.reverse
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails3-footnotes-4.0.0.pre.10 lib/rails-footnotes/notes/partials_note.rb
rails3-footnotes-4.0.0.pre.9 lib/rails-footnotes/notes/partials_note.rb
rails3-footnotes-4.0.0.pre.8 lib/rails-footnotes/notes/partials_note.rb
rails3-footnotes-4.0.0.pre.7 lib/rails-footnotes/notes/partials_note.rb
rails3-footnotes-4.0.0.pre.6 lib/rails-footnotes/notes/partials_note.rb
rails3-footnotes-4.0.0.pre.5 lib/rails-footnotes/notes/partials_note.rb