20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/code_buddy/stack_frame.rb', line 20
def code
@code ||= begin
html_args = { :line_numbers => :inline, :wrap => :span }
lines_of_code = File.new(path).readlines
first_line_to_show = [1, line-CODE_WINDOW].max
last_line_to_show = [lines_of_code.length, line + 1 + CODE_WINDOW].min
code_to_show = lines_of_code[first_line_to_show-1 .. last_line_to_show-1]
formatted_lines = CodeRay.scan(code_to_show.join, :ruby).
html(:line_numbers => :inline,
:wrap => :span,
:bold_every => false,
:line_number_start => first_line_to_show)
highlighted_line = line - first_line_to_show + 1
formatted_lines_array = formatted_lines.split("\n")
formatted_lines_array[highlighted_line-1] = "<span class='container selected'>#{formatted_lines_array[highlighted_line-1]}<span class='overlay'></span></span>"
formatted_lines_array.join("\n")
rescue => exception
"<span class=\"coderay\">Unable to read file:\n \"#{@path}\"</span>"
end
end
|