diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /app/presenters/blob_presenter.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'app/presenters/blob_presenter.rb')
-rw-r--r-- | app/presenters/blob_presenter.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index c198859aa4c..5835a77d0b9 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require 'ipynbdiff' class BlobPresenter < Gitlab::View::Presenter::Delegated include ApplicationHelper @@ -20,6 +21,17 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated ) end + def highlight_transformed(plain: nil) + load_all_blob_data + + Gitlab::Highlight.highlight( + blob.path, + transformed_blob_data, + language: transformed_blob_language, + plain: plain + ) + end + def plain_data return if blob.binary? @@ -50,6 +62,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated url_helpers.project_create_blob_path(project, ref_qualified_path) end + def pipeline_editor_path + project_ci_pipeline_editor_path(project, branch_name: blob.commit_id) if can_collaborate_with_project?(project) && blob.path == project.ci_config_path_or_default + end + def fork_and_edit_path fork_path_for_current_user(project, edit_blob_path) end @@ -107,4 +123,21 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated def language blob.language_from_gitattributes end + + def transformed_blob_language + @transformed_blob_language ||= blob.path.ends_with?('.ipynb') ? 'md' : language + end + + def transformed_blob_data + @transformed_blob ||= if blob.path.ends_with?('.ipynb') && blob.transformed_for_diff + IpynbDiff.transform(blob.data, + raise_errors: true, + options: { include_metadata: false, cell_decorator: :percent }) + end + + @transformed_blob ||= blob.data + rescue IpynbDiff::InvalidNotebookError => e + Gitlab::ErrorTracking.log_exception(e) + blob.data + end end |