summaryrefslogtreecommitdiff
path: root/app/helpers/search_helper.rb
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-09-14 13:29:23 +0300
committerValery Sizov <valery@gitlab.com>2016-09-14 14:31:02 +0300
commit6355041affb9b0b493d041d8b11772b8423bb32e (patch)
tree4764f436baba36b28258046a1277df5f554273b3 /app/helpers/search_helper.rb
parenteab72755cd9e0ac7f9ba6d30ad877b3aef14841b (diff)
downloadgitlab-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.rb31
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