From fb8a12c8fea422a9054fcbdb2e6b22770e9dfab3 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 10 Apr 2017 21:23:19 +0000 Subject: Don't show 'Copy content' button on text files that are not rendered as text --- app/models/blob.rb | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'app/models/blob.rb') diff --git a/app/models/blob.rb b/app/models/blob.rb index 801d3442803..55872acef51 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -42,12 +42,16 @@ class Blob < SimpleDelegator size && truncated? end + def extension + extname.downcase.delete('.') + end + def svg? text? && language && language.name == 'SVG' end def pdf? - name && File.extname(name) == '.pdf' + extension == 'pdf' end def ipython_notebook? @@ -55,11 +59,15 @@ class Blob < SimpleDelegator end def sketch? - binary? && extname.downcase.delete('.') == 'sketch' + binary? && extension == 'sketch' end def stl? - extname.downcase.delete('.') == 'stl' + extension == 'stl' + end + + def markup? + text? && Gitlab::MarkupHelper.markup?(name) end def size_within_svg_limits? @@ -77,8 +85,10 @@ class Blob < SimpleDelegator else 'text' end - elsif image? || svg? + elsif image? 'image' + elsif svg? + 'svg' elsif pdf? 'pdf' elsif ipython_notebook? @@ -87,8 +97,18 @@ class Blob < SimpleDelegator 'sketch' elsif stl? 'stl' + elsif markup? + if only_display_raw? + 'too_large' + else + 'markup' + end elsif text? - 'text' + if only_display_raw? + 'too_large' + else + 'text' + end else 'download' end -- cgit v1.2.1