Commit 59a9e1dfe9eafa1bdb077cfe2fe4ff3c99c858e1

Authored by Marcin Ciunelis
1 parent f64e20cf
Exists in master and in 1 other branch production

extract backtrace related helpers

app/helpers/backtrace_helper.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +module BacktraceHelper
  2 + # Group lines into sections of in-app files and external files
  3 + # (An implementation of Enumerable#chunk so we don't break 1.8.7 support.)
  4 + def grouped_lines(lines)
  5 + line_groups = []
  6 + lines.each do |line|
  7 + in_app = line.in_app?
  8 + if line_groups.last && line_groups.last[0] == in_app
  9 + line_groups.last[1] << line
  10 + else
  11 + line_groups << [in_app, [line]]
  12 + end
  13 + end
  14 + line_groups
  15 + end
  16 +end
... ...
app/helpers/backtrace_line_helper.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +module BacktraceLineHelper
  2 + def link_to_source_file(app, line, &block)
  3 + text = capture_haml(&block)
  4 + if line.in_app?
  5 + return link_to_github(app, line, text) if app.github_repo?
  6 + return link_to_bitbucket(app, line, text) if app.bitbucket_repo?
  7 + if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file)
  8 + # Return link to file on tracker if issue tracker supports this
  9 + return link_to_issue_tracker_file(app, line, text)
  10 + end
  11 + end
  12 + text
  13 + end
  14 +
  15 + def filepath_parts(file)
  16 + [file.split('/').last, file]
  17 + end
  18 +
  19 + def link_to_github(app, line, text = nil)
  20 + file_name, file_path = filepath_parts(line.file)
  21 + href = "%s#L%s" % [app.github_url_to_file(file_path), line.number]
  22 + link_to(text || file_name, href, :target => '_blank')
  23 + end
  24 +
  25 + def link_to_bitbucket(app, line, text = nil)
  26 + file_name, file_path = filepath_parts(line.file)
  27 + href = "%s#cl-%s" % [app.bitbucket_url_to_file(file_path), line.number]
  28 + link_to(text || file_name, href, :target => '_blank')
  29 + end
  30 +
  31 + def link_to_issue_tracker_file(app, line, text = nil)
  32 + file_name, file_path = filepath_parts(line.file_relative)
  33 + href = app.issue_tracker.url_to_file(file_path, line.number)
  34 + link_to(text || file_name, href, :target => '_blank')
  35 + end
  36 +
  37 + def path_for_backtrace_line(line)
  38 + path = File.dirname(line.file)
  39 + return '' if path == '.'
  40 + # Remove [PROJECT_ROOT]
  41 + path.gsub!('[PROJECT_ROOT]/', '')
  42 + # Make gem name bold if starts with [GEM_ROOT]/gems
  43 + path.gsub!(/\[GEM_ROOT\]\/gems\/([^\/]+)/, "<strong>\\1</strong>")
  44 + (path << '/').html_safe
  45 + end
  46 +
  47 + def file_for_backtrace_line(line)
  48 + file = File.basename(line.file)
  49 + end
  50 +
  51 +end
... ...
app/helpers/notices_helper.rb
... ... @@ -3,69 +3,5 @@ module NoticesHelper
3 3 def notice_atom_summary(notice)
4 4 render "notices/atom_entry.html.haml", :notice => notice
5 5 end
6   -
7   - def link_to_source_file(app, line, &block)
8   - text = capture_haml(&block)
9   - if line.in_app?
10   - return link_to_github(app, line, text) if app.github_repo?
11   - return link_to_bitbucket(app, line, text) if app.bitbucket_repo?
12   - if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file)
13   - # Return link to file on tracker if issue tracker supports this
14   - return link_to_issue_tracker_file(app, line, text)
15   - end
16   - end
17   - text
18   - end
19   -
20   - def filepath_parts(file)
21   - [file.split('/').last, file]
22   - end
23   -
24   - def link_to_github(app, line, text = nil)
25   - file_name, file_path = filepath_parts(line.file)
26   - href = "%s#L%s" % [app.github_url_to_file(file_path), line.number]
27   - link_to(text || file_name, href, :target => '_blank')
28   - end
29   -
30   - def link_to_bitbucket(app, line, text = nil)
31   - file_name, file_path = filepath_parts(line.file)
32   - href = "%s#cl-%s" % [app.bitbucket_url_to_file(file_path), line.number]
33   - link_to(text || file_name, href, :target => '_blank')
34   - end
35   -
36   - def link_to_issue_tracker_file(app, line, text = nil)
37   - file_name, file_path = filepath_parts(line.file_relative)
38   - href = app.issue_tracker.url_to_file(file_path, line.number)
39   - link_to(text || file_name, href, :target => '_blank')
40   - end
41   -
42   - # Group lines into sections of in-app files and external files
43   - # (An implementation of Enumerable#chunk so we don't break 1.8.7 support.)
44   - def grouped_lines(lines)
45   - line_groups = []
46   - lines.each do |line|
47   - in_app = line.in_app?
48   - if line_groups.last && line_groups.last[0] == in_app
49   - line_groups.last[1] << line
50   - else
51   - line_groups << [in_app, [line]]
52   - end
53   - end
54   - line_groups
55   - end
56   -
57   - def path_for_backtrace_line(line)
58   - path = File.dirname(line.file)
59   - return '' if path == '.'
60   - # Remove [PROJECT_ROOT]
61   - path.gsub!('[PROJECT_ROOT]/', '')
62   - # Make gem name bold if starts with [GEM_ROOT]/gems
63   - path.gsub!(/\[GEM_ROOT\]\/gems\/([^\/]+)/, "<strong>\\1</strong>")
64   - (path << '/').html_safe
65   - end
66   -
67   - def file_for_backtrace_line(line)
68   - file = File.basename(line.file)
69   - end
70 6 end
71 7  
... ...