17
18
19
20
21
22
23
24
25
26
27
28
29
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
|
# File 'lib/railsbp_in_browser.rb', line 17
def generate_html
puts "Generating the code climate ..."
`rails_best_practices . > rails_best_practices_output.html`
f = File.open("rails_best_practices_output.html")
of = File.open("code_climate.html", 'w')
reg = /.*\[31m(.*):([0-9]+) - (.*)\e.*/
f.each_line do |line|
next unless reg.match(line)
match_line = $2
match_file = $1
article_name = $3
if get_article_name(article_name)
of.puts("<h2><a target='_blank' href=#{get_article_name(article_name)}>#{article_name}</a></h2>")
else
of.puts("<h2>#{article_name}</h2>")
end
of.puts("<p>#{match_file.gsub(Dir.pwd, '')}:<strong style=\"background-color:darkseagreen\">#{match_line}</strong></p>")
ffa = File.open(match_file).to_a
of.puts("<div style=\"background-color:lightgrey;margin-left:50\">")
start = match_line.to_i - 5 > 0 ? match_line.to_i - 5 : 0
(start .. match_line.to_i + 5).each do |index|
if ffa[index] && (index + 1) == match_line.to_i
of.puts("<code style=\"background-color:darkseagreen\">#{index+1} - #{ffa[index].gsub('<', '<').gsub('>', '>')}</code><br>")
elsif ffa[index]
of.puts("<code>#{index+1} - #{ffa[index].gsub('<', '<').gsub('>', '>')}</code><br>")
end
end
of.puts("</div>")
end
f.close
of.close
puts "Open file in Chrome"
Launchy::Browser.run('./code_climate.html')
`rm rails_best_practices_output.html`
`rm code_climate.html`
end
|