class PrettyFace::Formatter::ReportStep::SnippetExtractor
Public Instance Methods
file_name_and_line(error_line)
click to toggle source
# File lib/pretty_face/formatter/report.rb, line 238 def file_name_and_line(error_line) if error_line =~ /(.*):(\d+)/ [$1, $2.to_i] end end
lines_around(file, line)
click to toggle source
# File lib/pretty_face/formatter/report.rb, line 260 def lines_around(file, line) if File.file?(file) # lines = File.open(file).read.split("\n") lines = File.readlines(file) min = [0, line-3].max max = [line+1, lines.length-1].min # lines[min..max].join("\n") lines[min..max].join else "# Couldn't get snippet for #{file}" end end
post_process(highlighted, offending_line)
click to toggle source
# File lib/pretty_face/formatter/report.rb, line 273 def post_process(highlighted, offending_line) new_lines = [] highlighted.split("\n").each_with_index do |line, i| new_line = "<span class=\"linenum\">#{offending_line+i-2}</span>#{line}" new_line = "<span class=\"offending\">#{new_line}</span>" if i == 2 new_lines << new_line end new_lines.join("\n") end
snippet(error)
click to toggle source
# File lib/pretty_face/formatter/report.rb, line 244 def snippet(error) raw_code, line, file = snippet_for(error[0]) highlighted = @@converter.convert(raw_code, false) "<pre class=\"ruby\"><strong>#{file + "\n"}</strong><code>#{post_process(highlighted, line)}</code></pre>" end
snippet_for(error_line)
click to toggle source
# File lib/pretty_face/formatter/report.rb, line 251 def snippet_for(error_line) file, line = file_name_and_line(error_line) if file [lines_around(file, line), line, file] else ["# Couldn't get snippet for #{error_line}", 1, 'File Unknown'] end end