Sha256: fd9eab6ee4ba89596221ea97cdb20ce6e173f7e786afa2524cdccd07192780f5

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 Bytes

Contents

require 'bunto/liquid_renderer/file'
require 'bunto/liquid_renderer/table'

module Bunto
  class LiquidRenderer
    def initialize(site)
      @site = site
      reset
    end

    def reset
      @stats = {}
    end

    def file(filename)
      filename = @site.in_source_dir(filename).sub(/\A#{Regexp.escape(@site.source)}\//, '')

      LiquidRenderer::File.new(self, filename).tap do
        @stats[filename] ||= {}
        @stats[filename][:count] ||= 0
        @stats[filename][:count] += 1
      end
    end

    def increment_bytes(filename, bytes)
      @stats[filename][:bytes] ||= 0
      @stats[filename][:bytes] += bytes
    end

    def increment_time(filename, time)
      @stats[filename][:time] ||= 0.0
      @stats[filename][:time] += time
    end

    def stats_table(n = 50)
      LiquidRenderer::Table.new(@stats).to_s(n)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bunto-3.0.0 lib/bunto/liquid_renderer.rb
bunto-2.0.0.pre lib/bunto/liquid_renderer.rb
bunto-1.0.0 lib/bunto/liquid_renderer.rb