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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
83e4fc18
Commit
83e4fc18
authored
Jan 14, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor highlighting lines
parent
3a1d0535
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
25 deletions
+4
-25
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+4
-25
No files found.
lib/gitlab/diff/highlight.rb
View file @
83e4fc18
...
...
@@ -32,23 +32,8 @@ module Gitlab
def
highlight
return
[]
if
@lines
.
empty?
extract_line_prefixes
update_diff_lines
end
private
def
text_lines
@text_lines
||=
@lines
.
map
(
&
:text
)
end
def
extract_line_prefixes
@diff_line_prefixes
||=
text_lines
.
map
{
|
line
|
line
.
sub!
(
/\A((\+|\-))/
,
''
);
$1
}
end
def
update_diff_lines
@lines
.
each_with_index
do
|
line
,
i
|
line_prefix
=
@diff_line_prefixes
[
i
]
||
' '
line_prefix
=
line
.
text
.
match
(
/\A([+-])/
)
?
$1
:
' '
# ignore highlighting for "match" lines
next
if
line
.
type
==
'match'
...
...
@@ -62,24 +47,18 @@ 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
.
sub
(
/\A\s/
,
line_prefix
).
html_safe
if
highlighted_line
line
.
text
=
highlighted_line
.
insert
(
0
,
line_prefix
).
html_safe
if
highlighted_line
end
@lines
end
def
old_lines
@old_lines
||=
begin
lines
=
self
.
class
.
process_file
(
diff_repository
,
diff_old_ref
,
diff_old_path
)
lines
.
map!
{
|
line
|
"
#{
line
}
"
}
end
@old_lines
||=
self
.
class
.
process_file
(
diff_repository
,
diff_old_ref
,
diff_old_path
)
end
def
new_lines
@new_lines
||=
begin
lines
=
self
.
class
.
process_file
(
diff_repository
,
diff_new_ref
,
diff_new_path
)
lines
.
map!
{
|
line
|
"
#{
line
}
"
}
end
@new_lines
||=
self
.
class
.
process_file
(
diff_repository
,
diff_new_ref
,
diff_new_path
)
end
end
end
...
...
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