Explain how viewers are selected from RICH_VIEWERS
This commit is contained in:
parent
88380a04c6
commit
787866a91f
|
|
@ -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::Image,
|
BlobViewer::Markup,
|
||||||
BlobViewer::PDF,
|
|
||||||
BlobViewer::Sketch,
|
|
||||||
BlobViewer::BinarySTL,
|
|
||||||
BlobViewer::TextSTL,
|
|
||||||
BlobViewer::Notebook,
|
BlobViewer::Notebook,
|
||||||
BlobViewer::SVG,
|
BlobViewer::SVG,
|
||||||
BlobViewer::Markup,
|
|
||||||
|
BlobViewer::Image,
|
||||||
|
BlobViewer::Sketch,
|
||||||
|
|
||||||
|
BlobViewer::PDF,
|
||||||
|
|
||||||
|
BlobViewer::BinarySTL,
|
||||||
|
BlobViewer::TextSTL,
|
||||||
].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
|
||||||
|
|
||||||
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) }
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue