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
Jérome Perrin
gitlab-ce
Commits
6cbe3867
Commit
6cbe3867
authored
Jun 08, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dm-blob-file-type' into 'master'
Add Blob#file_type convenience method See merge request !11982
parents
299a3a9a
369d681e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
1 deletion
+13
-1
app/models/blob.rb
app/models/blob.rb
+4
-0
app/models/blob_viewer/base.rb
app/models/blob_viewer/base.rb
+1
-1
spec/models/blob_spec.rb
spec/models/blob_spec.rb
+8
-0
No files found.
app/models/blob.rb
View file @
6cbe3867
...
@@ -155,6 +155,10 @@ class Blob < SimpleDelegator
...
@@ -155,6 +155,10 @@ class Blob < SimpleDelegator
@extension
||=
extname
.
downcase
.
delete
(
'.'
)
@extension
||=
extname
.
downcase
.
delete
(
'.'
)
end
end
def
file_type
Gitlab
::
FileDetector
.
type_of
(
path
)
end
def
video?
def
video?
UploaderHelper
::
VIDEO_EXT
.
include?
(
extension
)
UploaderHelper
::
VIDEO_EXT
.
include?
(
extension
)
end
end
...
...
app/models/blob_viewer/base.rb
View file @
6cbe3867
...
@@ -52,7 +52,7 @@ module BlobViewer
...
@@ -52,7 +52,7 @@ module BlobViewer
def
self
.
can_render?
(
blob
,
verify_binary:
true
)
def
self
.
can_render?
(
blob
,
verify_binary:
true
)
return
false
if
verify_binary
&&
binary?
!=
blob
.
binary?
return
false
if
verify_binary
&&
binary?
!=
blob
.
binary?
return
true
if
extensions
&
.
include?
(
blob
.
extension
)
return
true
if
extensions
&
.
include?
(
blob
.
extension
)
return
true
if
file_types
&
.
include?
(
Gitlab
::
FileDetector
.
type_of
(
blob
.
path
)
)
return
true
if
file_types
&
.
include?
(
blob
.
file_type
)
false
false
end
end
...
...
spec/models/blob_spec.rb
View file @
6cbe3867
...
@@ -199,6 +199,14 @@ describe Blob do
...
@@ -199,6 +199,14 @@ describe Blob do
end
end
end
end
describe
'#file_type'
do
it
'returns the file type'
do
blob
=
fake_blob
(
path:
'README.md'
)
expect
(
blob
.
file_type
).
to
eq
(
:readme
)
end
end
describe
'#simple_viewer'
do
describe
'#simple_viewer'
do
context
'when the blob is empty'
do
context
'when the blob is empty'
do
it
'returns an empty viewer'
do
it
'returns an empty viewer'
do
...
...
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