diff options
author | Valery Sizov <valery@gitlab.com> | 2016-09-14 13:29:23 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2016-09-14 14:31:02 +0300 |
commit | 6355041affb9b0b493d041d8b11772b8423bb32e (patch) | |
tree | 4764f436baba36b28258046a1277df5f554273b3 /app/helpers/search_helper.rb | |
parent | eab72755cd9e0ac7f9ba6d30ad877b3aef14841b (diff) | |
download | gitlab-ce-6355041affb9b0b493d041d8b11772b8423bb32e.tar.gz |
Backport search_helper changes from EEbackport_to_search_helper_from_ee
Diffstat (limited to 'app/helpers/search_helper.rb')
-rw-r--r-- | app/helpers/search_helper.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index e523c46e879..8a7446b7cc7 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -30,6 +30,37 @@ module SearchHelper "Showing #{from} - #{to} of #{count} #{scope.humanize(capitalize: false)} for \"#{term}\"" end + def parse_search_result(result) + ref = nil + filename = nil + basename = nil + startline = 0 + + result.each_line.each_with_index do |line, index| + if line =~ /^.*:.*:\d+:/ + ref, filename, startline = line.split(':') + startline = startline.to_i - index + extname = Regexp.escape(File.extname(filename)) + basename = filename.sub(/#{extname}$/, '') + break + end + end + + data = "" + + result.each_line do |line| + data << line.sub(ref, '').sub(filename, '').sub(/^:-\d+-/, '').sub(/^::\d+:/, '') + end + + OpenStruct.new( + filename: filename, + basename: basename, + ref: ref, + startline: startline, + data: data + ) + end + private # Autocomplete results for various settings pages |