2020-01-22 07:08:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SnippetBlobPresenter < BlobPresenter
|
2020-07-06 14:09:13 -04:00
|
|
|
include GitlabRoutingHelper
|
|
|
|
|
2022-05-31 05:08:17 -04:00
|
|
|
delegator_override_with Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
|
|
|
|
|
2021-09-21 05:12:21 -04:00
|
|
|
presents ::SnippetBlob
|
|
|
|
|
2020-02-12 13:09:21 -05:00
|
|
|
def rich_data
|
2020-03-02 16:08:01 -05:00
|
|
|
return unless blob.rich_viewer
|
2020-01-22 07:08:40 -05:00
|
|
|
|
2020-03-02 16:08:01 -05:00
|
|
|
render_rich_partial
|
2020-02-11 13:08:58 -05:00
|
|
|
end
|
|
|
|
|
2020-01-22 07:08:40 -05:00
|
|
|
def raw_path
|
2020-08-18 08:10:16 -04:00
|
|
|
snippet_blob_raw_route(only_path: true)
|
|
|
|
end
|
2020-07-06 14:09:13 -04:00
|
|
|
|
2020-08-18 08:10:16 -04:00
|
|
|
def raw_url
|
|
|
|
snippet_blob_raw_route
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
|
|
|
|
2021-09-02 11:11:35 -04:00
|
|
|
def raw_directory
|
|
|
|
raw_path.rpartition("/").first + "/"
|
|
|
|
end
|
|
|
|
|
2021-06-28 17:10:13 -04:00
|
|
|
def raw_plain_data
|
|
|
|
blob.data unless blob.binary?
|
|
|
|
end
|
|
|
|
|
2020-01-22 07:08:40 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def snippet
|
2020-02-25 04:09:10 -05:00
|
|
|
blob.container
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
|
|
|
|
2022-02-03 07:18:57 -05:00
|
|
|
def gitattr_language
|
2020-01-22 07:08:40 -05:00
|
|
|
nil
|
|
|
|
end
|
2020-03-02 16:08:01 -05:00
|
|
|
|
|
|
|
def render_rich_partial
|
|
|
|
renderer.render("projects/blob/viewers/_#{blob.rich_viewer.partial_name}",
|
2021-09-02 11:11:35 -04:00
|
|
|
locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path, blob_raw_url: raw_url, parent_dir_raw_path: raw_directory },
|
2020-03-02 16:08:01 -05:00
|
|
|
layout: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def renderer
|
|
|
|
proxy = Warden::Proxy.new({}, Warden::Manager.new({})).tap do |proxy_instance|
|
|
|
|
proxy_instance.set_user(current_user, scope: :user)
|
|
|
|
end
|
|
|
|
|
|
|
|
ApplicationController.renderer.new('warden' => proxy)
|
|
|
|
end
|
2020-08-18 08:10:16 -04:00
|
|
|
|
|
|
|
def snippet_blob_raw_route(only_path: false)
|
2020-10-08 05:08:40 -04:00
|
|
|
return gitlab_raw_snippet_url(snippet, only_path: only_path) unless snippet.repository_exists?
|
|
|
|
|
2020-10-06 14:08:49 -04:00
|
|
|
gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path)
|
2020-08-18 08:10:16 -04:00
|
|
|
end
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
2021-11-19 04:13:48 -05:00
|
|
|
|
|
|
|
SnippetBlobPresenter.prepend_mod
|