backtrace_line_helper.rb
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
module BacktraceLineHelper
def link_to_source_file(app, line, &block)
text = capture_haml(&block)
if line.in_app?
return link_to_github(app, line, text) if app.github_repo?
return link_to_bitbucket(app, line, text) if app.bitbucket_repo?
if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file)
# Return link to file on tracker if issue tracker supports this
return link_to_issue_tracker_file(app, line, text)
end
end
text
end
def filepath_parts(file)
[file.split('/').last, file]
end
def link_to_github(app, line, text = nil)
file_name, file_path = filepath_parts(line.file)
href = "%s#L%s" % [app.github_url_to_file(file_path), line.number]
link_to(text || file_name, href, :target => '_blank')
end
def link_to_bitbucket(app, line, text = nil)
file_name, file_path = filepath_parts(line.file)
href = "%s#cl-%s" % [app.bitbucket_url_to_file(file_path), line.number]
link_to(text || file_name, href, :target => '_blank')
end
def link_to_issue_tracker_file(app, line, text = nil)
file_name, file_path = filepath_parts(line.file_relative)
href = app.issue_tracker.url_to_file(file_path, line.number)
link_to(text || file_name, href, :target => '_blank')
end
def path_for_backtrace_line(line)
path = File.dirname(line.file)
return '' if path == '.'
# Remove [PROJECT_ROOT]
path.gsub!('[PROJECT_ROOT]/', '')
# Make gem name bold if starts with [GEM_ROOT]/gems
path.gsub!(/\[GEM_ROOT\]\/gems\/([^\/]+)/, "<strong>\\1</strong>")
(path << '/').html_safe
end
def file_for_backtrace_line(line)
file = File.basename(line.file)
end
end