diff options
Diffstat (limited to 'app/presenters/blob_presenter.rb')
-rw-r--r-- | app/presenters/blob_presenter.rb | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index cff935d51b5..56dd056b9bc 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true class BlobPresenter < Gitlab::View::Presenter::Delegated + include ApplicationHelper + include BlobHelper + include DiffHelper + include TreeHelper + include ChecksCollaboration + presents :blob def highlight(to: nil, plain: nil) @@ -14,16 +20,68 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated ) end + def plain_data + return if blob.binary? + + highlight(plain: false) + end + def web_url - Gitlab::Routing.url_helpers.project_blob_url(blob.repository.project, File.join(blob.commit_id, blob.path)) + url_helpers.project_blob_url(project, ref_qualified_path) end def web_path - Gitlab::Routing.url_helpers.project_blob_path(blob.repository.project, File.join(blob.commit_id, blob.path)) + url_helpers.project_blob_path(project, ref_qualified_path) + end + + def edit_blob_path + url_helpers.project_edit_blob_path(project, ref_qualified_path) + end + + def raw_path + url_helpers.project_raw_path(project, ref_qualified_path) + end + + def replace_path + url_helpers.project_create_blob_path(project, ref_qualified_path) + end + + def fork_and_edit_path + fork_path_for_current_user(project, edit_blob_path) + end + + def ide_fork_and_edit_path + fork_path_for_current_user(project, ide_edit_path) + end + + def can_modify_blob? + super(blob, project, blob.commit_id) + end + + def ide_edit_path + super(project, blob.commit_id, blob.path) + end + + def external_storage_url + return unless static_objects_external_storage_enabled? + + external_storage_url_or_path(url_helpers.project_raw_url(project, ref_qualified_path)) end private + def url_helpers + Gitlab::Routing.url_helpers + end + + def project + blob.repository.project + end + + def ref_qualified_path + File.join(blob.commit_id, blob.path) + end + def load_all_blob_data blob.load_all_data! if blob.respond_to?(:load_all_data!) end |