Class: Fukuzatsu::Formatters::Html
- Inherits:
-
Object
- Object
- Fukuzatsu::Formatters::Html
show all
- Includes:
- Base
- Defined in:
- lib/fukuzatsu/formatters/html.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Base
#filename, included, #initialize, #output_directory, #output_path, #path_to_results
Class Method Details
.index(summaries, base_output_path) ⇒ Object
Instance Method Details
#columns ⇒ Object
15
16
17
|
# File 'lib/fukuzatsu/formatters/html.rb', line 15
def columns
["Class", "Method", "Complexity"]
end
|
#content ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/fukuzatsu/formatters/html.rb', line 19
def content
Haml::Engine.new(output_template).render(
Object.new, {
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 ⇒ Object
34
35
36
37
38
39
40
|
# 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 ⇒ Object
42
43
44
|
# File 'lib/fukuzatsu/formatters/html.rb', line 42
def file_extension
".htm"
end
|
46
47
48
|
# File 'lib/fukuzatsu/formatters/html.rb', line 46
def formatter
Rouge::Formatters::HTML.new(line_numbers: true)
end
|
50
51
52
|
# File 'lib/fukuzatsu/formatters/html.rb', line 50
def
columns.map{|col| "<th>#{col}</th>"}.join("\r\n")
end
|
#lexer ⇒ Object
54
55
56
|
# File 'lib/fukuzatsu/formatters/html.rb', line 54
def lexer
Rouge::Lexers::Ruby.new
end
|
#output_template ⇒ Object
58
59
60
|
# File 'lib/fukuzatsu/formatters/html.rb', line 58
def output_template
File.read(File.dirname(__FILE__) + "/templates/output.html.haml")
end
|
#preprocessed ⇒ Object
62
63
64
|
# File 'lib/fukuzatsu/formatters/html.rb', line 62
def preprocessed
formatter.format(lexer.lex(summary.raw_source))
end
|
#rows ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# 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
|