summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Dávila <rdavila84@gmail.com>2016-01-13 11:39:15 -0500
committerRubén Dávila <rdavila84@gmail.com>2016-01-13 11:39:15 -0500
commit0f0af19139db71255934e9a7a5b5cd86420b7186 (patch)
tree61b8a2b9610e6a1d47fbb5dc3a4b97bcbd1d6bc7
parent48c45ba9a8a9a5536a3d501e40536cc5b73062a1 (diff)
downloadgitlab-ce-0f0af19139db71255934e9a7a5b5cd86420b7186.tar.gz
Little refactor for usage of html_safe. #3945
-rw-r--r--app/helpers/diff_helper.rb9
-rw-r--r--app/views/projects/blob/diff.html.haml2
-rw-r--r--app/views/projects/diffs/_parallel_view.html.haml4
-rw-r--r--lib/gitlab/diff/highlight.rb4
4 files changed, 10 insertions, 9 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index 0ec532a9a90..d49e22e8c84 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -1,4 +1,6 @@
module DiffHelper
+ BLANK_SPACE = "&nbsp;".html_safe
+
def diff_view
params[:view] == 'parallel' ? 'parallel' : 'inline'
end
@@ -83,7 +85,7 @@ module DiffHelper
elsif next_type == 'old' || next_type.nil?
# Left side has text removed, right side doesn't have any change
# No next line code, no new line number, no new line text
- line = [type, line_old, full_line, line_code, next_type, nil, "&nbsp;", nil]
+ line = [type, line_old, full_line, line_code, next_type, nil, BLANK_SPACE, nil]
lines.push(line)
end
elsif type == 'new'
@@ -93,7 +95,7 @@ module DiffHelper
next
else
# Change is only on the right side, left side has no change
- line = [nil, nil, "&nbsp;", 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)
end
end
@@ -113,8 +115,7 @@ module DiffHelper
if line.blank?
" &nbsp;".html_safe
else
- # Return line if it isn't a String, it helps when it's Numeric
- line.is_a?(String) ? line.html_safe : line
+ line.html_safe
end
end
diff --git a/app/views/projects/blob/diff.html.haml b/app/views/projects/blob/diff.html.haml
index ef23876677a..2e913802be1 100644
--- a/app/views/projects/blob/diff.html.haml
+++ b/app/views/projects/blob/diff.html.haml
@@ -11,7 +11,7 @@
%td.old_line.diff-line-num{data: {linenumber: line_old}}
= link_to raw(line_old), "#"
%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
%tr.line_holder{ id: @form.to }
diff --git a/app/views/projects/diffs/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml
index 1ad54d1848b..e9108c04cef 100644
--- a/app/views/projects/diffs/_parallel_view.html.haml
+++ b/app/views/projects/diffs/_parallel_view.html.haml
@@ -20,7 +20,7 @@
= link_to raw(line_number_left), "##{line_code_left}", id: line_code_left
- if @comments_allowed && can?(current_user, :create_note, @project)
= 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'
- new_line_class = 'new'
@@ -33,7 +33,7 @@
= link_to raw(line_number_right), "##{new_line_code}", id: new_line_code
- if @comments_allowed && can?(current_user, :create_note, @project)
= 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
- comments_left, comments_right = organize_comments(type_left, type_right, line_code_left, line_code_right)
diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb
index 0b6a348acbc..f940b57d596 100644
--- a/lib/gitlab/diff/highlight.rb
+++ b/lib/gitlab/diff/highlight.rb
@@ -22,7 +22,7 @@ module Gitlab
content = blob.data
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
def self.formatter
@@ -73,7 +73,7 @@ module Gitlab
# Only update text if line is found. This will prevent
# 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
@lines