diff options
author | Mark Chao <mchao@gitlab.com> | 2018-09-06 17:48:57 +0800 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2018-10-30 15:44:55 +0800 |
commit | 32f9cf8ce3dd337bf3b1683c5872171c253f0d27 (patch) | |
tree | da6f8077d458283ae1da56cbc9e282c87cdeba0a /app | |
parent | 6580de78bb52323fcafaaf4d2e770590e4f1c586 (diff) | |
download | gitlab-ce-32f9cf8ce3dd337bf3b1683c5872171c253f0d27.tar.gz |
Add BlobPresenter for highlighting
Force FoundBlob to use BlobPresenter
Diffstat (limited to 'app')
-rw-r--r-- | app/models/blob.rb | 4 | ||||
-rw-r--r-- | app/presenters/blob_presenter.rb | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index e5854415dd2..425ba69c073 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true -# Blob is a Rails-specific wrapper around Gitlab::Git::Blob objects +# Blob is a Rails-specific wrapper around Gitlab::Git::Blob, SnippetBlob and Ci::ArtifactBlob class Blob < SimpleDelegator + include Presentable + CACHE_TIME = 60 # Cache raw blobs referred to by a (mutable) ref for 1 minute CACHE_TIME_IMMUTABLE = 3600 # Cache blobs referred to by an immutable reference for 1 hour 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 |