Class: Dcov::Generator

Inherits:
Object
  • Object
show all
Includes:
StatsRenderer::Helpers
Defined in:
lib/dcov_builder.rb

Overview

Generates HTML output

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Generator

Returns a new instance of Generator.



16
17
18
# File 'lib/dcov_builder.rb', line 16

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/dcov_builder.rb', line 15

def data
  @data
end

Instance Method Details

#build_stats_bodyObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dcov_builder.rb', line 30

def build_stats_body
  output = ""
  num_classes = File.read("#{Continuous4r::WORK_DIR}/rdoc/rdoc.log").split(/$/).select { |l| l =~ /^Classes:/ }[0].strip.split(/Classes:/)[1].strip.to_f
  num_modules = File.read("#{Continuous4r::WORK_DIR}/rdoc/rdoc.log").split(/$/).select { |l| l =~ /^Modules:/ }[0].strip.split(/Modules:/)[1].strip.to_f
  num_methods = File.read("#{Continuous4r::WORK_DIR}/rdoc/rdoc.log").split(/$/).select { |l| l =~ /^Methods:/ }[0].strip.split(/Methods:/)[1].strip.to_f
  global_coverage = ((class_coverage.to_f * num_classes) + (module_coverage.to_f * num_modules) + (method_coverage.to_f * num_methods)) / (num_classes + num_modules + num_methods)
  output << "<h3 #{Utils.percent_to_css_style(global_coverage.to_i)}>Global coverage percentage : #{global_coverage.to_i}%</h3>\n"
  output << "<h3>Summary</h3><p>\n"
  output << "<table class='bodyTable' style='width: 200px;'><tr><th>Type</th><th>Coverage</th></tr>"
  output << "<tr class='a'><td><b>Class</b></td><td style='text-align: right;'>#{class_coverage}%</td></tr>\n"
  output << "<tr class='b'><td><b>Module</b></td><td style='text-align: right;'>#{module_coverage}%</td></tr>\n"
  output << "<tr class='a'><td><b>Method</b></td><td style='text-align: right;'>#{method_coverage}%</td></tr></table>\n"
  output << "</p>\n\n"

  if data[:structured].length > 0
    output << "<h3>Details</h3><p><table class='bodyTable'><tr><th>Class/Module name</th><th>Method name</th></tr>\n"
  end
  indice = 0
  nbtr = 0
  data[:structured].each do |key,value|
    class_error_presence = (value[0].comment.nil? or value[0].comment == '') unless value[0].is_a?(Dcov::TopLevel)
    method_error_presence = false
    count_method_error_presence = 0
    value[1].each do |itm|
      method_error_presence = true if (itm.comment.nil? or itm.comment == '')
      count_method_error_presence += 1 if (itm.comment.nil? or itm.comment == '')
    end
    if class_error_presence == true or method_error_presence == true
      nbtr += 1
      output << "<tr class='#{indice % 2 == 0 ? 'a' : 'b'}'>"
      if class_error_presence == true or method_error_presence == true
        output << "<td>#{"<b>" if class_error_presence == true}#{key.is_a?(String) ? key : key.full_name }#{"</b> in <a href='xdoclet/#{value[0].in_files.first.file_absolute_name.gsub(/\//,'_')}.html' target='_blank'>#{value[0].in_files.first.file_absolute_name}</a>" if class_error_presence == true}</td>"
      else
        output << "<td>&#160;</td>"
      end
      if count_method_error_presence == 1
        value[1].each do |itm|
          output << ((itm.comment.nil? || itm.comment == '') ? "<td><ol><li><b>#{itm.name}</b> in <a href='xdoclet/#{itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, '').gsub(/\//,'_')}.html##{itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, ':\1').split(/:/)[1]}' target='_blank'>#{itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, ':\1')}</a></b></li></ol></td>" : "")
        end
      elsif count_method_error_presence > 1
        output << "<td><ol>"
        value[1].each do |itm|
          output << ((itm.comment.nil? || itm.comment == '') ? "<li><b>#{itm.name}</b> in <a href='xdoclet/#{itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, '').gsub(/\//,'_')}.html##{itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, ':\1').split(/:/)[1]}' target='_blank'>#{itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, ':\1')}</a></b></li>" : "")
        end
        output << "</ol></td>"
      else
        output << "<td>&#160;</td>"
      end
      if class_error_presence == true or method_error_presence == true
        indice += 1
        output << "</tr>"
      end
    end
  end
  if nbtr == 0
    output << "<tr class='a'><td colspan='2'>There is no undocumented Ruby code.</td></tr>"
  end
  output << "</table>"
  output
end


91
92
93
94
# File 'lib/dcov_builder.rb', line 91

def build_stats_footer
  output = ""
  output << "</ol>\n\n</body></html>"
end

#build_stats_headerObject



24
25
26
27
28
# File 'lib/dcov_builder.rb', line 24

def build_stats_header
  # Little CSS, a little HTML...
  output = ""
  output << """<h2>Dcov results</h2>\n\n<p><a href='http://dcov.rubyforge.org' target='_blank'>Dcov</a> is a documentation coverage analyzer for ruby.</p>"""
end

#to_sObject



20
21
22
# File 'lib/dcov_builder.rb', line 20

def to_s
  build_stats_header + build_stats_body + build_stats_footer
end