Sha256: c39c7b0abdebc48464c1c387b35437a9e58011183c4bba002b61ab10e77d9c6c

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'cgi'
require 'erb'

module Coco

  # I format coverages information into html files.
  # @todo document and change name to HtmlFilesFormatter
  class HtmlFormatter < Formatter

    def initialize(raw_coverages)
      super(raw_coverages, [])
      @formatted_output_files = {}
      @context = nil
      @template = Template.open File.join(Coco::ROOT, 'template/file.erb')
    end

    def format
      @raw_coverages.each do |filename, coverage|
        build_html filename, coverage
      end
      @formatted_output_files
    end

    private

    def build_html(filename, coverage)
      source = File.readlines filename
      lines = []
      source.each_with_index do |line, index|
        lines << [index+1, CGI.escapeHTML(line.chomp), coverage[index]]
      end
      @context = Context.new filename, lines
      @formatted_output_files[filename] = @template.result(@context.get_binding)
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coco-0.12.0 lib/coco/formatter/html_formatter.rb
coco-0.11.0 lib/coco/formatter/html_formatter.rb