Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
0f0af191
Commit
0f0af191
authored
Jan 13, 2016
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Little refactor for usage of html_safe. #3945
parent
48c45ba9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
9 deletions
+10
-9
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+5
-4
app/views/projects/blob/diff.html.haml
app/views/projects/blob/diff.html.haml
+1
-1
app/views/projects/diffs/_parallel_view.html.haml
app/views/projects/diffs/_parallel_view.html.haml
+2
-2
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+2
-2
No files found.
app/helpers/diff_helper.rb
View file @
0f0af191
module
DiffHelper
BLANK_SPACE
=
" "
.
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
,
" "
,
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
,
" "
,
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?
" "
.
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
...
...
app/views/projects/blob/diff.html.haml
View file @
0f0af191
...
...
@@ -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
}
...
...
app/views/projects/diffs/_parallel_view.html.haml
View file @
0f0af191
...
...
@@ -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
)
...
...
lib/gitlab/diff/highlight.rb
View file @
0f0af191
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment