2020-01-22 07:08:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SnippetBlobPresenter < BlobPresenter
|
2020-02-12 13:09:21 -05:00
|
|
|
def rich_data
|
2020-01-22 07:08:40 -05:00
|
|
|
return if blob.binary?
|
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-02-12 13:09:21 -05:00
|
|
|
def plain_data
|
2020-02-11 13:08:58 -05:00
|
|
|
return if blob.binary?
|
|
|
|
|
2020-03-02 16:08:01 -05:00
|
|
|
highlight(plain: false)
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def raw_path
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
|
|
|
raw_project_snippet_path(snippet.project, snippet)
|
|
|
|
else
|
|
|
|
raw_snippet_path(snippet)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def snippet
|
2020-02-25 04:09:10 -05:00
|
|
|
blob.container
|
2020-01-22 07:08:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def language
|
|
|
|
nil
|
|
|
|
end
|
2020-03-02 16:08:01 -05:00
|
|
|
|
|
|
|
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-01-22 07:08:40 -05:00
|
|
|
end
|