Commit c69a0779 authored by Douwe Maan's avatar Douwe Maan

Address feedback

parent fed9dcd9
......@@ -224,4 +224,20 @@ module BlobHelper
"it is stored in LFS"
end
end
def blob_render_error_options(viewer, error)
options = []
if error == :too_large && viewer.can_override_max_size?
options << link_to('load it anyway', url_for(params.merge(viewer: viewer.type, override_max_size: true, format: nil)))
end
if viewer.rich? && viewer.blob.rendered_as_text?(override_max_size: true)
options << link_to('view the source', '#', class: 'js-blob-viewer-switcher', data: { viewer: 'simple' })
end
options << link_to('download it', blob_raw_url, target: '_blank', rel: 'noopener noreferrer')
options
end
end
......@@ -107,12 +107,10 @@ class Blob < SimpleDelegator
end
def rich_viewer_class
if invalid_lfs_pointer? || empty?
nil
else
return if invalid_lfs_pointer? || empty?
rich_viewers_classes.find { |viewer_class| viewer_class.can_render?(self) }
end
end
def simple_viewer
@simple_viewer ||= simple_viewer_class.new(self)
......
......@@ -2,7 +2,7 @@ module BlobViewer
class Base
class_attribute :partial_name, :type, :extensions, :client_side, :text_based, :switcher_icon, :switcher_title, :max_size, :absolute_max_size
delegate :partial_path, :rich?, :simple?, :client_side?, :text_based?, to: :class
delegate :partial_path, :rich?, :simple?, :client_side?, :server_side?, :text_based?, to: :class
attr_reader :blob
......@@ -26,7 +26,7 @@ module BlobViewer
client_side
end
def server_side?
def self.server_side?
!client_side?
end
......
module BlobViewer
class Download < Base
include Simple
# We pretend the Download viewer is rendered client-side so that it doesn't
# attempt to load the entire blob contents.
# We treat the Download viewer as if it renders the content client-side,
# so that it doesn't attempt to load the entire blob contents and is
# rendered synchronously instead of loaded asynchronously.
include ClientSide
self.partial_name = 'download'
......
- simple_viewer = blob.simple_viewer
- rich_viewer = blob.rich_viewer
- active_viewer = rich_viewer && params[:viewer] != 'simple' ? :rich : :simple
- rich_viewer_active = rich_viewer && params[:viewer] != 'simple'
= render 'projects/blob/viewer_wrapper', viewer: simple_viewer, hidden: (active_viewer != :simple)
= render 'projects/blob/viewer_wrapper', viewer: simple_viewer, hidden: rich_viewer_active
- if rich_viewer
= render 'projects/blob/viewer_wrapper', viewer: rich_viewer, hidden: (active_viewer != :rich)
= render 'projects/blob/viewer_wrapper', viewer: rich_viewer, hidden: !rich_viewer_active
- reason = blob_render_error_reason(viewer, error)
- options = []
- if error == :too_large && viewer.can_override_max_size?
- options << link_to('load it anyway', url_for(params.merge(viewer: viewer.type, override_max_size: true, format: nil)))
- if viewer.rich? && viewer.blob.rendered_as_text?(override_max_size: true)
- options << link_to('view the source', '#', class: 'js-blob-viewer-switcher', data: { viewer: 'simple' })
- options << link_to('download it', blob_raw_url, target: '_blank', rel: 'noopener noreferrer')
.file-content.code
.nothing-here-block
The #{viewer.switcher_title} could not be displayed because #{reason}.
The #{viewer.switcher_title} could not be displayed because #{blob_render_error_reason(viewer, error)}.
You can
= options.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ').html_safe
= blob_render_error_options(viewer, error).to_sentence(two_words_connector: ' or ', last_word_connector: ', or ').html_safe
instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment