Sha256: 0ae9e1b194bb835ae66aeff3c4eab12f9b110e227e77b9fed08930601d454ea6

Contents?: true

Size: 977 Bytes

Versions: 9

Compression:

Stored size: 977 Bytes

Contents

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

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_PATH,'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, line.chomp.gsub(/</, '&lt;').gsub(/>/, '&gt;'), coverage[index]]
      end
      @context = Context.new filename, lines
      @formatted_output_files[filename] = @template.result(@context.get_binding)
    end
    
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
coco-0.10.0 lib/coco/formatter/html_formatter.rb
coco-0.9 lib/coco/formatter/html_formatter.rb
coco-0.8 lib/coco/formatter/html_formatter.rb
coco-0.7.1 lib/coco/formatter/html_formatter.rb
coco-0.7 lib/coco/formatter/html_formatter.rb
coco-0.6 lib/coco/formatter/html_formatter.rb
coco-0.5.1 lib/coco/formatter/html_formatter.rb
coco-0.5 lib/coco/formatter/html_formatter.rb
coco-0.4.2 lib/coco/formatter/html_formatter.rb