Commit 0f0af191 authored by Rubén Dávila's avatar Rubén Dávila

Little refactor for usage of html_safe. #3945

parent 48c45ba9
module DiffHelper module DiffHelper
BLANK_SPACE = " ".html_safe
def diff_view def diff_view
params[:view] == 'parallel' ? 'parallel' : 'inline' params[:view] == 'parallel' ? 'parallel' : 'inline'
end end
...@@ -83,7 +85,7 @@ module DiffHelper ...@@ -83,7 +85,7 @@ module DiffHelper
elsif next_type == 'old' || next_type.nil? elsif next_type == 'old' || next_type.nil?
# Left side has text removed, right side doesn't have any change # Left side has text removed, right side doesn't have any change
# No next line code, no new line number, no new line text # No next line code, no new line number, no new line text
line = [type, line_old, full_line, line_code, next_type, nil, " ", nil] line = [type, line_old, full_line, line_code, next_type, nil, BLANK_SPACE, nil]
lines.push(line) lines.push(line)
end end
elsif type == 'new' elsif type == 'new'
...@@ -93,7 +95,7 @@ module DiffHelper ...@@ -93,7 +95,7 @@ module DiffHelper
next next
else else
# Change is only on the right side, left side has no change # Change is only on the right side, left side has no change
line = [nil, nil, " ", line_code, type, line_new, full_line, line_code] line = [nil, nil, BLANK_SPACE, line_code, type, line_new, full_line, line_code]
lines.push(line) lines.push(line)
end end
end end
...@@ -113,8 +115,7 @@ module DiffHelper ...@@ -113,8 +115,7 @@ module DiffHelper
if line.blank? if line.blank?
"  ".html_safe "  ".html_safe
else else
# Return line if it isn't a String, it helps when it's Numeric line.html_safe
line.is_a?(String) ? line.html_safe : line
end end
end end
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
%td.old_line.diff-line-num{data: {linenumber: line_old}} %td.old_line.diff-line-num{data: {linenumber: line_old}}
= link_to raw(line_old), "#" = link_to raw(line_old), "#"
%td.new_line= link_to raw(line_new) , "#" %td.new_line= link_to raw(line_new) , "#"
%td.line_content.noteable_line= "#{' ' * @form.indent}#{line}".html_safe %td.line_content.noteable_line==#{' ' * @form.indent}#{line}
- if @form.unfold? && @form.bottom? && @form.to < @blob.loc - if @form.unfold? && @form.bottom? && @form.to < @blob.loc
%tr.line_holder{ id: @form.to } %tr.line_holder{ id: @form.to }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
= link_to raw(line_number_left), "##{line_code_left}", id: line_code_left = link_to raw(line_number_left), "##{line_code_left}", id: line_code_left
- if @comments_allowed && can?(current_user, :create_note, @project) - if @comments_allowed && can?(current_user, :create_note, @project)
= link_to_new_diff_note(line_code_left, 'old') = link_to_new_diff_note(line_code_left, 'old')
%td.line_content{class: "parallel noteable_line #{type_left} #{line_code_left}", "line_code" => line_code_left }= line_content_left.html_safe %td.line_content{class: "parallel noteable_line #{type_left} #{line_code_left}", "line_code" => line_code_left }= line_content_left
- if type_right == 'new' - if type_right == 'new'
- new_line_class = 'new' - new_line_class = 'new'
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
= link_to raw(line_number_right), "##{new_line_code}", id: new_line_code = link_to raw(line_number_right), "##{new_line_code}", id: new_line_code
- if @comments_allowed && can?(current_user, :create_note, @project) - if @comments_allowed && can?(current_user, :create_note, @project)
= link_to_new_diff_note(line_code_right, 'new') = link_to_new_diff_note(line_code_right, 'new')
%td.line_content.parallel{class: "noteable_line #{new_line_class} #{new_line_code}", "line_code" => new_line_code}= line_content_right.html_safe %td.line_content.parallel{class: "noteable_line #{new_line_class} #{new_line_code}", "line_code" => new_line_code}= line_content_right
- if @reply_allowed - if @reply_allowed
- comments_left, comments_right = organize_comments(type_left, type_right, line_code_left, line_code_right) - comments_left, comments_right = organize_comments(type_left, type_right, line_code_left, line_code_right)
......
...@@ -22,7 +22,7 @@ module Gitlab ...@@ -22,7 +22,7 @@ module Gitlab
content = blob.data content = blob.data
lexer = Rouge::Lexer.guess(filename: file_name, source: content).new rescue Rouge::Lexers::PlainText.new lexer = Rouge::Lexer.guess(filename: file_name, source: content).new rescue Rouge::Lexers::PlainText.new
formatter.format(lexer.lex(content)).lines formatter.format(lexer.lex(content)).lines.map!(&:html_safe)
end end
def self.formatter def self.formatter
...@@ -73,7 +73,7 @@ module Gitlab ...@@ -73,7 +73,7 @@ module Gitlab
# Only update text if line is found. This will prevent # Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content. # issues with submodules given the line only exists in diff content.
line.text = highlighted_line.gsub!(/\A\s/, line_prefix) if highlighted_line line.text = highlighted_line.gsub!(/\A\s/, line_prefix).html_safe if highlighted_line
end end
@lines @lines
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment