notices_helper.rb
2.05 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# encoding: utf-8
module NoticesHelper
def in_app_backtrace_line?(line)
!!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))})
end
def notice_atom_summary(notice)
render "notices/atom_entry.html.haml", :notice => notice
end
def link_to_source_file(app, line, &block)
text = capture_haml(&block)
if in_app_backtrace_line?(line)
return link_to_github(app, line, text) if app.github_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.gsub('[PROJECT_ROOT]', '')]
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_issue_tracker_file(app, line, text = nil)
file_name, file_path = filepath_parts(line['file'])
href = app.issue_tracker.url_to_file(file_path, line['number'])
link_to(text || file_name, href, :target => '_blank')
end
# Group lines into sections of in-app files and external files
# (An implementation of Enumerable#chunk so we don't break 1.8.7 support.)
def grouped_lines(lines)
line_groups = []
lines.each do |line|
in_app = in_app_backtrace_line?(line)
if line_groups.last && line_groups.last[0] == in_app
line_groups.last[1] << line
else
line_groups << [in_app, [line]]
end
end
line_groups
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