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
787866a9
Commit
787866a9
authored
Apr 26, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Explain how viewers are selected from RICH_VIEWERS
parent
88380a04
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
app/models/blob.rb
app/models/blob.rb
+27
-7
app/models/blob_viewer/text_stl.rb
app/models/blob_viewer/text_stl.rb
+1
-6
No files found.
app/models/blob.rb
View file @
787866a9
...
@@ -5,17 +5,37 @@ class Blob < SimpleDelegator
...
@@ -5,17 +5,37 @@ class Blob < SimpleDelegator
MAXIMUM_TEXT_HIGHLIGHT_SIZE
=
1
.
megabyte
MAXIMUM_TEXT_HIGHLIGHT_SIZE
=
1
.
megabyte
# Finding a viewer for a blob happens based only on extension and whether the
# blob is binary or text, which means 1 blob should only be matched by 1 viewer,
# and the order of these viewers doesn't really matter.
#
# However, when the blob is an LFS pointer, we cannot know for sure whether the
# file being pointed to is binary or text. In this case, we match only on
# extension, preferring binary viewers over text ones if both exist, since the
# large files referred to in "Large File Storage" are much more likely to be
# binary than text.
#
# `.stl` files, for example, exist in both binary and text forms, and are
# handled by different viewers (`BinarySTL` and `TextSTL`) depending on blob
# type. LFS pointers to `.stl` files are assumed to always be the binary kind,
# and use the `BinarySTL` viewer.
RICH_VIEWERS
=
[
RICH_VIEWERS
=
[
BlobViewer
::
Markup
,
BlobViewer
::
Notebook
,
BlobViewer
::
SVG
,
BlobViewer
::
Image
,
BlobViewer
::
Image
,
BlobViewer
::
PDF
,
BlobViewer
::
Sketch
,
BlobViewer
::
Sketch
,
BlobViewer
::
PDF
,
BlobViewer
::
BinarySTL
,
BlobViewer
::
BinarySTL
,
BlobViewer
::
TextSTL
,
BlobViewer
::
TextSTL
,
BlobViewer
::
Notebook
,
BlobViewer
::
SVG
,
BlobViewer
::
Markup
,
].
freeze
].
freeze
BINARY_VIEWERS
=
RICH_VIEWERS
.
select
(
&
:binary?
).
freeze
TEXT_VIEWERS
=
RICH_VIEWERS
.
select
(
&
:text?
).
freeze
attr_reader
:project
attr_reader
:project
# Wrap a Gitlab::Git::Blob object, or return nil when given nil
# Wrap a Gitlab::Git::Blob object, or return nil when given nil
...
@@ -147,11 +167,11 @@ class Blob < SimpleDelegator
...
@@ -147,11 +167,11 @@ class Blob < SimpleDelegator
classes
=
classes
=
if
valid_lfs_pointer?
if
valid_lfs_pointer?
RICH
_VIEWERS
BINARY_VIEWERS
+
TEXT
_VIEWERS
elsif
binary?
elsif
binary?
RICH_VIEWERS
.
select
(
&
:binary?
)
BINARY_VIEWERS
else
# text
else
# text
RICH_VIEWERS
.
select
(
&
:text?
)
TEXT_VIEWERS
end
end
classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
...
...
app/models/blob_viewer/text_stl.rb
View file @
787866a9
module
BlobViewer
module
BlobViewer
class
TextSTL
<
Base
class
TextSTL
<
BinarySTL
include
Rich
include
ClientSide
self
.
partial_name
=
'stl'
self
.
extensions
=
%w(stl)
self
.
binary
=
false
self
.
binary
=
false
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