diff options
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 |