summaryrefslogtreecommitdiff
path: root/lib/gitlab/diff/highlight.rb
diff options
context:
space:
mode:
authorRubén Dávila <rdavila84@gmail.com>2016-01-12 17:36:08 -0500
committerRubén Dávila <rdavila84@gmail.com>2016-01-12 17:36:08 -0500
commit6e3358a5077f5c6052e733722cd6baa63e43c081 (patch)
tree491f20322268c46c58ec35c1389fe238c05d5a04 /lib/gitlab/diff/highlight.rb
parentc0385488fbfaf1285122793cea417e607c8e771e (diff)
downloadgitlab-ce-6e3358a5077f5c6052e733722cd6baa63e43c081.tar.gz
Remove no longer required code. #3945
Diffstat (limited to 'lib/gitlab/diff/highlight.rb')
-rw-r--r--lib/gitlab/diff/highlight.rb51
1 files changed, 9 insertions, 42 deletions
diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb
index d0137ab5f08..14cf98e24a2 100644
--- a/lib/gitlab/diff/highlight.rb
+++ b/lib/gitlab/diff/highlight.rb
@@ -44,74 +44,41 @@ module Gitlab
return [] if @lines.empty?
extract_line_prefixes
-
- @code = unescape_html(raw_content)
- @highlighted_code = formatter.format(lexer.lex(@code))
-
- is_diff_line? ? update_diff_lines : @highlighted_code.lines
+ update_diff_lines
end
private
- def is_diff_line?
- @lines.first.is_a?(Gitlab::Diff::Line)
- end
-
def text_lines
- @text_lines ||= (is_diff_line? ? @lines.map(&:text) : @lines)
- end
-
- def raw_content
- @raw_content ||= text_lines.join(is_diff_line? ? "\n" : nil)
+ @text_lines ||= @lines.map(&:text)
end
def extract_line_prefixes
- @diff_line_prefixes ||= begin
- if is_diff_line?
- text_lines.map { |line| line.sub!(/\A((\+|\-))/, '');$1 }
- else
- []
- end
- end
+ @diff_line_prefixes ||= text_lines.map { |line| line.sub!(/\A((\+|\-))/, '');$1 }
end
def update_diff_lines
- @highlighted_code.lines.each_with_index do |line, i|
- diff_line = @lines[i]
+ @lines.each_with_index do |line, i|
line_prefix = @diff_line_prefixes[i] || ' '
# ignore highlighting for "match" lines
- next if diff_line.type == 'match'
+ next if line.type == 'match'
- case diff_line.type
+ case line.type
when 'new', nil
- line = new_lines[diff_line.new_pos - 1]
+ highlighted_line = new_lines[line.new_pos - 1]
when 'old'
- line = old_lines[diff_line.old_pos - 1]
+ highlighted_line = old_lines[line.old_pos - 1]
end
# Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content.
- diff_line.text = line.gsub!(/\A\s/, line_prefix) if line
+ line.text = highlighted_line.gsub!(/\A\s/, line_prefix) if line
end
@lines
end
- def lexer
- Rouge::Lexer.guess(filename: @file_name, source: @code).new rescue Rouge::Lexers::PlainText.new
- end
-
- def unescape_html(content)
- text = CGI.unescapeHTML(content)
- text.gsub!('&nbsp;', ' ')
- text
- end
-
- def formatter
- self.class.formatter
- end
-
def old_lines
@old_lines ||= begin
lines = self.class.process_file(diff_repository, diff_old_ref, diff_old_path)