debian-mirror-gitlab/app/presenters/snippet_blob_presenter.rb

53 lines
1.1 KiB
Ruby
Raw Normal View History

2020-03-09 13:42:32 +05:30
# frozen_string_literal: true
class SnippetBlobPresenter < BlobPresenter
2020-07-28 23:09:34 +05:30
include GitlabRoutingHelper
2020-03-09 13:42:32 +05:30
def rich_data
return if blob.binary?
2020-04-08 14:13:33 +05:30
return unless blob.rich_viewer
2020-03-09 13:42:32 +05:30
2020-04-08 14:13:33 +05:30
render_rich_partial
2020-03-09 13:42:32 +05:30
end
def plain_data
return if blob.binary?
2020-04-08 14:13:33 +05:30
highlight(plain: false)
2020-03-09 13:42:32 +05:30
end
def raw_path
2020-07-28 23:09:34 +05:30
return gitlab_raw_snippet_blob_path(blob) if snippet_multiple_files?
gitlab_raw_snippet_path(snippet)
2020-03-09 13:42:32 +05:30
end
private
2020-07-28 23:09:34 +05:30
def snippet_multiple_files?
blob.container.repository_exists? && Feature.enabled?(:snippet_multiple_files, current_user)
end
2020-03-09 13:42:32 +05:30
def snippet
2020-04-08 14:13:33 +05:30
blob.container
2020-03-09 13:42:32 +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}",
locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path },
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-03-09 13:42:32 +05:30
end