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
Léo-Paul Géneau
gitlab-ce
Commits
32f9cf8c
Commit
32f9cf8c
authored
Sep 06, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BlobPresenter for highlighting
Force FoundBlob to use BlobPresenter
parent
6580de78
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
1 deletion
+82
-1
app/models/blob.rb
app/models/blob.rb
+3
-1
app/presenters/blob_presenter.rb
app/presenters/blob_presenter.rb
+14
-0
lib/gitlab/search_results.rb
lib/gitlab/search_results.rb
+5
-0
spec/presenters/blob_presenter_spec.rb
spec/presenters/blob_presenter_spec.rb
+60
-0
No files found.
app/models/blob.rb
View file @
32f9cf8c
# frozen_string_literal: true
# frozen_string_literal: true
# Blob is a Rails-specific wrapper around Gitlab::Git::Blob
objects
# Blob is a Rails-specific wrapper around Gitlab::Git::Blob
, SnippetBlob and Ci::ArtifactBlob
class
Blob
<
SimpleDelegator
class
Blob
<
SimpleDelegator
include
Presentable
CACHE_TIME
=
60
# Cache raw blobs referred to by a (mutable) ref for 1 minute
CACHE_TIME
=
60
# Cache raw blobs referred to by a (mutable) ref for 1 minute
CACHE_TIME_IMMUTABLE
=
3600
# Cache blobs referred to by an immutable reference for 1 hour
CACHE_TIME_IMMUTABLE
=
3600
# Cache blobs referred to by an immutable reference for 1 hour
...
...
app/presenters/blob_presenter.rb
0 → 100644
View file @
32f9cf8c
# frozen_string_literal: true
class
BlobPresenter
<
Gitlab
::
View
::
Presenter
::
Simple
presents
:blob
def
highlight
(
plain:
nil
)
Gitlab
::
Highlight
.
highlight
(
blob
.
path
,
blob
.
data
,
language:
blob
.
language_from_gitattributes
,
plain:
(
plain
||
blob
.
no_highlighting?
)
)
end
end
lib/gitlab/search_results.rb
View file @
32f9cf8c
...
@@ -4,6 +4,7 @@ module Gitlab
...
@@ -4,6 +4,7 @@ module Gitlab
class
SearchResults
class
SearchResults
class
FoundBlob
class
FoundBlob
include
EncodingHelper
include
EncodingHelper
include
Presentable
attr_reader
:id
,
:filename
,
:basename
,
:ref
,
:startline
,
:data
,
:project_id
attr_reader
:id
,
:filename
,
:basename
,
:ref
,
:startline
,
:data
,
:project_id
...
@@ -31,6 +32,10 @@ module Gitlab
...
@@ -31,6 +32,10 @@ module Gitlab
def
language_from_gitattributes
def
language_from_gitattributes
nil
nil
end
end
def
present
super
(
presenter_class:
BlobPresenter
)
end
end
end
attr_reader
:current_user
,
:query
,
:per_page
attr_reader
:current_user
,
:query
,
:per_page
...
...
spec/presenters/blob_presenter_spec.rb
0 → 100644
View file @
32f9cf8c
# frozen_string_literal: true
require
'spec_helper'
describe
BlobPresenter
,
:seed_helper
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
,
''
)
}
let
(
:git_blob
)
do
Gitlab
::
Git
::
Blob
.
find
(
repository
,
'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6'
,
'files/ruby/regex.rb'
)
end
let
(
:blob
)
{
Blob
.
new
(
git_blob
)
}
describe
'#highlight'
do
subject
{
described_class
.
new
(
blob
)
}
it
'returns highlighted content'
do
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ruby/regex.rb'
,
git_blob
.
data
,
plain:
false
,
language:
nil
)
subject
.
highlight
end
context
'with :plain'
do
it
'returns plain content when no_highlighting? is true'
do
allow
(
blob
).
to
receive
(
:no_highlighting?
).
and_return
(
true
)
subject
.
highlight
end
it
'returns plain content when :plain is true'
do
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ruby/regex.rb'
,
git_blob
.
data
,
plain:
true
,
language:
nil
)
subject
.
highlight
(
plain:
true
)
end
it
'returns plain content when :plain is false, but no_highlighting? is true'
do
allow
(
blob
).
to
receive
(
:no_highlighting?
).
and_return
(
true
)
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ruby/regex.rb'
,
git_blob
.
data
,
plain:
true
,
language:
nil
)
subject
.
highlight
(
plain:
false
)
end
end
context
'gitlab-language contains a match'
do
before
do
allow
(
blob
).
to
receive
(
:language_from_gitattributes
).
and_return
(
'ruby'
)
end
it
'passes language to inner call'
do
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ruby/regex.rb'
,
git_blob
.
data
,
plain:
false
,
language:
'ruby'
)
subject
.
highlight
end
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