From 32f9cf8ce3dd337bf3b1683c5872171c253f0d27 Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Thu, 6 Sep 2018 17:48:57 +0800 Subject: Add BlobPresenter for highlighting Force FoundBlob to use BlobPresenter --- app/presenters/blob_presenter.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/presenters/blob_presenter.rb (limited to 'app/presenters/blob_presenter.rb') diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb new file mode 100644 index 00000000000..2bca413876c --- /dev/null +++ b/app/presenters/blob_presenter.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class BlobPresenter < Gitlab::View::Presenter::Simple + presents :blob + + def highlight(plain: nil) + Gitlab::Highlight.highlight( + blob.path, + blob.data, + language: blob.language_from_gitattributes, + plain: (plain || blob.no_highlighting?) + ) + end +end -- cgit v1.2.1 From bc14e4ed1024efa1e0a411bd59e1339fb1af20c0 Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Tue, 11 Sep 2018 12:37:44 +0800 Subject: Move :plain option to Highlight class This is to DRY the repeated file size check. Move spec and constants to Highlight --- app/presenters/blob_presenter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/presenters/blob_presenter.rb') diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index 2bca413876c..9980f6cd8a6 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -8,7 +8,7 @@ class BlobPresenter < Gitlab::View::Presenter::Simple blob.path, blob.data, language: blob.language_from_gitattributes, - plain: (plain || blob.no_highlighting?) + plain: plain ) end end -- cgit v1.2.1 From 623b7f3055e0dec033795b9d4eb625b781773834 Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Thu, 4 Oct 2018 12:04:13 +0800 Subject: Centralize loading blob data before highlighting --- app/presenters/blob_presenter.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/presenters/blob_presenter.rb') diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index 9980f6cd8a6..6323c1b3389 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -4,6 +4,8 @@ class BlobPresenter < Gitlab::View::Presenter::Simple presents :blob def highlight(plain: nil) + blob.load_all_data! if blob.respond_to?(:load_all_data!) + Gitlab::Highlight.highlight( blob.path, blob.data, -- cgit v1.2.1