Sha256: 637edd79b7889ea982681486a6858983318163e0c4ca8b9df88fda0ec8bde2e7

Contents?: true

Size: 1.18 KB

Versions: 21

Compression:

Stored size: 1.18 KB

Contents

# -*- coding: utf-8 -*-
class Remnant
  class Template
    class Trace
      def start(template_name)
        rendering = Remnant::Template::Rendering.new(template_name)
        rendering.start_time = Time.now
        @current.add(rendering)
        @current = rendering
      end

      def finished(template_name)
        @current.end_time = Time.now
        @current = @current.parent
      end

      def initialize
        @current = root
      end

      def total_time
        root.child_time
      end

      def root
        @root ||= Remnant::Template::Rendering.new('root')
      end

      def log(logger, rendering)
        rendering.results.map do |key, result|

          #
          line = Remnant.color
          line += "#{'   ' * (result['depth'] - 1)}#{result['depth'] > 1 ? '└ ' : ''}"
          line += "#{result['time'].to_i}ms (#{result['exclusive'].to_i}ms)"
          line += Remnant.color(true)
          line += ' ' * ((line.size >= 50 ? 10 : 50 - line.size) - (result['depth'] == 1 ? 2 : 0))
          line += "#{key}"

          logger.info line

          rendering.children.map do |child|
            log(logger, child)
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
remnant-1.0.0 lib/remnant/template/trace.rb
remnant-0.4.10 lib/remnant/template/trace.rb
remnant-0.4.9 lib/remnant/template/trace.rb
remnant-0.4.8 lib/remnant/template/trace.rb
remnant-0.4.7 lib/remnant/template/trace.rb
remnant-0.4.6 lib/remnant/template/trace.rb
remnant-0.4.5 lib/remnant/template/trace.rb
remnant-0.9.5 lib/remnant/template/trace.rb
remnant-0.9.4 lib/remnant/template/trace.rb
remnant-0.4.4 lib/remnant/template/trace.rb
remnant-0.9.3 lib/remnant/template/trace.rb
remnant-0.9.2 lib/remnant/template/trace.rb
remnant-0.9.1 lib/remnant/template/trace.rb
remnant-0.9.0 lib/remnant/template/trace.rb
remnant-0.4.3 lib/remnant/template/trace.rb
remnant-0.4.2 lib/remnant/template/trace.rb
remnant-0.4.1 lib/remnant/template/trace.rb
remnant-0.4.0 lib/remnant/template/trace.rb
remnant-0.3.3 lib/remnant/template/trace.rb
remnant-0.3.2 lib/remnant/template/trace.rb