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
8b079315
Commit
8b079315
authored
Dec 30, 2015
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A bit of refactoring. #3945
parent
d8327562
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
10 deletions
+12
-10
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+1
-1
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+8
-8
lib/rouge/lexers/gitlab_diff.rb
lib/rouge/lexers/gitlab_diff.rb
+2
-0
spec/lib/gitlab/diff/highlight_spec.rb
spec/lib/gitlab/diff/highlight_spec.rb
+1
-1
No files found.
lib/gitlab/diff/file.rb
View file @
8b079315
...
...
@@ -16,7 +16,7 @@ module Gitlab
end
def
highlighted_diff_lines
Gitlab
::
Diff
::
Highlight
.
process_diff_lines
(
self
)
Gitlab
::
Diff
::
Highlight
.
process_diff_lines
(
new_path
,
diff_lines
)
end
def
mode_changed?
...
...
lib/gitlab/diff/highlight.rb
View file @
8b079315
module
Gitlab
module
Diff
class
Highlight
def
self
.
process_diff_lines
(
diff_file
)
processor
=
new
(
diff_file
)
def
self
.
process_diff_lines
(
file_name
,
diff_lines
)
processor
=
new
(
file_name
,
diff_lines
)
processor
.
highlight
end
def
initialize
(
diff_file
)
text_lines
=
diff_
file
.
diff_
lines
.
map
(
&
:text
)
@
diff_file
=
diff_fil
e
@diff_lines
=
diff_
file
.
diff_
lines
def
initialize
(
file_name
,
diff_lines
)
text_lines
=
diff_lines
.
map
(
&
:text
)
@
file_name
=
file_nam
e
@diff_lines
=
diff_lines
@diff_line_prefixes
=
text_lines
.
map
{
|
line
|
line
.
sub!
(
/\A((\+|\-)\s*)/
,
''
);
$1
}
@raw_lines
=
text_lines
.
join
(
"
\n
"
)
end
...
...
@@ -32,7 +32,7 @@ module Gitlab
end
def
lexer
parent
=
Rouge
::
Lexer
.
guess
(
filename:
@
diff_file
.
new_path
,
source:
@code
).
new
rescue
Rouge
::
Lexers
::
PlainText
.
new
parent
=
Rouge
::
Lexer
.
guess
(
filename:
@
file_name
,
source:
@code
).
new
rescue
Rouge
::
Lexers
::
PlainText
.
new
Rouge
::
Lexers
::
GitlabDiff
.
new
(
parent_lexer:
parent
)
end
...
...
@@ -43,7 +43,7 @@ module Gitlab
end
def
formatter
@formatter
||=
Rouge
::
Formatters
::
HTMLGitlab
.
new
(
Rouge
::
Formatters
::
HTMLGitlab
.
new
(
nowrap:
true
,
cssclass:
'code highlight'
,
lineanchors:
true
,
...
...
lib/rouge/lexers/gitlab_diff.rb
View file @
8b079315
...
...
@@ -2,6 +2,8 @@ Rouge::Token::Tokens.token(:InlineDiff, 'idiff')
module
Rouge
module
Lexers
# This new Lexer is required in order to avoid the inline diff markup
# to be tokenized, it will be rendered as raw HTML code if that happens.
class
GitlabDiff
<
RegexLexer
title
"GitLab Diff"
tag
'gitlab_diff'
...
...
spec/lib/gitlab/diff/highlight_spec.rb
View file @
8b079315
...
...
@@ -9,7 +9,7 @@ describe Gitlab::Diff::Highlight, lib: true do
let
(
:diff_file
)
{
Gitlab
::
Diff
::
File
.
new
(
diff
)
}
describe
'.process_diff_lines'
do
let
(
:diff_lines
)
{
Gitlab
::
Diff
::
Highlight
.
process_diff_lines
(
diff_file
)
}
let
(
:diff_lines
)
{
Gitlab
::
Diff
::
Highlight
.
process_diff_lines
(
diff_file
.
new_path
,
diff_file
.
diff_lines
)
}
it
'should return Gitlab::Diff::Line elements'
do
expect
(
diff_lines
.
first
).
to
be_an_instance_of
(
Gitlab
::
Diff
::
Line
)
...
...
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