2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SnippetBlobPresenter < BlobPresenter
|
2020-07-28 23:09:34 +05:30
|
|
|
include GitlabRoutingHelper
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
presents ::SnippetBlob
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def rich_data
|
2020-04-08 14:13:33 +05:30
|
|
|
return unless blob.rich_viewer
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
render_rich_partial
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def raw_path
|
2020-10-24 23:57:45 +05:30
|
|
|
snippet_blob_raw_route(only_path: true)
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def raw_url
|
|
|
|
snippet_blob_raw_route
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def raw_directory
|
|
|
|
raw_path.rpartition("/").first + "/"
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def raw_plain_data
|
|
|
|
blob.data unless blob.binary?
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def snippet
|
2020-04-08 14:13:33 +05:30
|
|
|
blob.container
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def language
|
|
|
|
nil
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def render_rich_partial
|
|
|
|
renderer.render("projects/blob/viewers/_#{blob.rich_viewer.partial_name}",
|
2021-11-11 11:23:49 +05:30
|
|
|
locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path, blob_raw_url: raw_url, parent_dir_raw_path: raw_directory },
|
2020-04-08 14:13:33 +05:30
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
def snippet_blob_raw_route(only_path: false)
|
2021-01-03 14:25:43 +05:30
|
|
|
return gitlab_raw_snippet_url(snippet, only_path: only_path) unless snippet.repository_exists?
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|