diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-26 15:16:38 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 12:23:27 -0500 |
commit | 787866a91f4a7125336707dc9e58d338d0d6fde2 (patch) | |
tree | 8f405b389805cd842e2163b4b0fb29fb557598f2 | |
parent | 88380a04c629d21d39e59a6066cec63b8db89126 (diff) | |
download | gitlab-ce-787866a91f4a7125336707dc9e58d338d0d6fde2.tar.gz |
Explain how viewers are selected from RICH_VIEWERS
-rw-r--r-- | app/models/blob.rb | 34 | ||||
-rw-r--r-- | app/models/blob_viewer/text_stl.rb | 7 |
2 files changed, 28 insertions, 13 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index e87b418d242..290df5d5520 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -5,17 +5,37 @@ class Blob < SimpleDelegator 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 = [ + BlobViewer::Markup, + BlobViewer::Notebook, + BlobViewer::SVG, + BlobViewer::Image, - BlobViewer::PDF, BlobViewer::Sketch, + + BlobViewer::PDF, + BlobViewer::BinarySTL, BlobViewer::TextSTL, - BlobViewer::Notebook, - BlobViewer::SVG, - BlobViewer::Markup, ].freeze + BINARY_VIEWERS = RICH_VIEWERS.select(&:binary?).freeze + TEXT_VIEWERS = RICH_VIEWERS.select(&:text?).freeze + attr_reader :project # Wrap a Gitlab::Git::Blob object, or return nil when given nil @@ -147,11 +167,11 @@ class Blob < SimpleDelegator classes = if valid_lfs_pointer? - RICH_VIEWERS + BINARY_VIEWERS + TEXT_VIEWERS elsif binary? - RICH_VIEWERS.select(&:binary?) + BINARY_VIEWERS else # text - RICH_VIEWERS.select(&:text?) + TEXT_VIEWERS end classes.find { |viewer_class| viewer_class.can_render?(self) } diff --git a/app/models/blob_viewer/text_stl.rb b/app/models/blob_viewer/text_stl.rb index 2bb136a2702..8184dc0104c 100644 --- a/app/models/blob_viewer/text_stl.rb +++ b/app/models/blob_viewer/text_stl.rb @@ -1,10 +1,5 @@ module BlobViewer - class TextSTL < Base - include Rich - include ClientSide - - self.partial_name = 'stl' - self.extensions = %w(stl) + class TextSTL < BinarySTL self.binary = false end end |