class Fukuzatsu::Formatters::Html

Public Class Methods

index(summaries, base_output_path) click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 11
def self.index(summaries, base_output_path)
  Fukuzatsu::Formatters::HtmlIndex.new(summaries, base_output_path).export
end

Public Instance Methods

columns() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 15
def columns
  ["Class", "Method", "Complexity"]
end
content() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 19
def content
  Haml::Engine.new(output_template).render(
    Object.new, {
      header: header,
      rows: rows,
      source_lines: preprocessed,
      class_name: summary.container_name,
      average_complexity: sprintf("%0.2f", summary.average_complexity),
      path_to_file: summary.source_file,
      date: Time.now.strftime("%Y/%m/%d"),
      time: Time.now.strftime("%l:%M %P")
    }
  )
end
export() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 34
def export
  begin
    File.open(File.expand_path(path_to_results), 'w') {|outfile| outfile.write(content)}
  rescue Exception => e
    puts "Unable to write output: #{e} #{e.backtrace}"
  end
end
file_extension() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 42
def file_extension
  ".htm"
end
formatter() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 46
def formatter
  Rouge::Formatters::HTML.new(line_numbers: true)
end
header() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 50
def header
  columns.map{|col| "<th>#{col}</th>"}.join("\r\n")
end
lexer() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 54
def lexer
  Rouge::Lexers::Ruby.new
end
output_template() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 58
def output_template
  File.read(File.dirname(__FILE__) + "/templates/output.html.haml")
end
preprocessed() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 62
def preprocessed
  formatter.format(lexer.lex(summary.raw_source))
end
rows() click to toggle source
# File lib/fukuzatsu/formatters/html.rb, line 66
def rows
  i = 0
  summary.summaries.inject([]) do |a, summary|
    i += 1
    a << "<tr class='#{i % 2 == 1 ? 'even' : 'odd'}'>"
    a << "  <td>#{summary.container_name}</td>"
    a << "  <td>#{summary.entity_name}</td>"
    a << "  <td>#{summary.complexity}</td>"
    a << "</tr>"
    a
  end.join("\r\n")
end