From d40e1f547ea9e31e822229bb808aaa6b9201f473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 3 May 2017 13:22:03 +0200 Subject: Enable the Style/TrailingCommaInLiteral cop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the EnforcedStyleForMultiline: no_comma option. Signed-off-by: Rémy Coutable --- app/models/blob.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/blob.rb') diff --git a/app/models/blob.rb b/app/models/blob.rb index eaf0b713122..8452a96e909 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -33,7 +33,7 @@ class Blob < SimpleDelegator BlobViewer::PDF, BlobViewer::BinarySTL, - BlobViewer::TextSTL, + BlobViewer::TextSTL ].freeze BINARY_VIEWERS = RICH_VIEWERS.select(&:binary?).freeze -- cgit v1.2.1 From 08706f683725dcfbda1708ddf079347d989fbef1 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 8 May 2017 18:50:23 -0500 Subject: Implement auxiliary blob viewers --- app/models/blob.rb | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'app/models/blob.rb') diff --git a/app/models/blob.rb b/app/models/blob.rb index 8452a96e909..63a81c0e3bd 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -34,10 +34,13 @@ class Blob < SimpleDelegator BlobViewer::BinarySTL, BlobViewer::TextSTL - ].freeze + ].sort_by { |v| v.binary? ? 0 : 1 }.freeze - BINARY_VIEWERS = RICH_VIEWERS.select(&:binary?).freeze - TEXT_VIEWERS = RICH_VIEWERS.select(&:text?).freeze + AUXILIARY_VIEWERS = [ + BlobViewer::GitlabCiYml, + BlobViewer::RouteMap, + BlobViewer::License + ].freeze attr_reader :project @@ -154,6 +157,12 @@ class Blob < SimpleDelegator @rich_viewer = rich_viewer_class&.new(self) end + def auxiliary_viewer + return @auxiliary_viewer if defined?(@auxiliary_viewer) + + @auxiliary_viewer = auxiliary_viewer_class&.new(self) + end + def rendered_as_text?(ignore_errors: true) simple_viewer.text? && (ignore_errors || simple_viewer.render_error.nil?) end @@ -180,17 +189,18 @@ class Blob < SimpleDelegator end def rich_viewer_class + viewer_class_from(RICH_VIEWERS) + end + + def auxiliary_viewer_class + viewer_class_from(AUXILIARY_VIEWERS) + end + + def viewer_class_from(classes) return if empty? || external_storage_error? - classes = - if stored_externally? - BINARY_VIEWERS + TEXT_VIEWERS - elsif binary? - BINARY_VIEWERS - else # text - TEXT_VIEWERS - end + verify_binary = !stored_externally? - classes.find { |viewer_class| viewer_class.can_render?(self) } + classes.find { |viewer_class| viewer_class.can_render?(self, verify_binary: verify_binary) } end end -- cgit v1.2.1