diff options
author | Mark Chao <mchao@gitlab.com> | 2018-09-11 07:37:44 +0300 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2018-10-30 10:44:55 +0300 |
commit | bc14e4ed1024efa1e0a411bd59e1339fb1af20c0 (patch) | |
tree | 249ac6ce57b9758d3472dd4b1319527636b72f44 /app | |
parent | 39ae9a59a59615092fbef189466f37c34f4a7fb1 (diff) |
Move :plain option to Highlight class
This is to DRY the repeated file size check.
Move spec and constants to Highlight
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/blob_helper.rb | 1 | ||||
-rw-r--r-- | app/models/blob.rb | 6 | ||||
-rw-r--r-- | app/presenters/blob_presenter.rb | 2 | ||||
-rw-r--r-- | app/views/search/results/_snippet_blob.html.haml | 2 |
4 files changed, 2 insertions, 9 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 52cf9d12287..638744a1426 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -2,7 +2,6 @@ module BlobHelper def highlight(file_name, file_content, language: nil, plain: false) - plain ||= file_content.length > Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE highlighted = Gitlab::Highlight.highlight(file_name, file_content, plain: plain, language: language) raw %(<pre class="code highlight"><code>#{highlighted}</code></pre>) diff --git a/app/models/blob.rb b/app/models/blob.rb index 425ba69c073..57c813e3775 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -7,8 +7,6 @@ class Blob < SimpleDelegator 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 - MAXIMUM_TEXT_HIGHLIGHT_SIZE = 1.megabyte - # Finding a viewer for a blob happens based only on extension and whether the # blob is binary or text, which means 1 blob should only be matched by 1 viewer, # and the order of these viewers doesn't really matter. @@ -123,10 +121,6 @@ class Blob < SimpleDelegator end end - def no_highlighting? - raw_size && raw_size > MAXIMUM_TEXT_HIGHLIGHT_SIZE - end - def empty? raw_size == 0 end 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 diff --git a/app/views/search/results/_snippet_blob.html.haml b/app/views/search/results/_snippet_blob.html.haml index 92ea6f281f4..b4ecd7bbae9 100644 --- a/app/views/search/results/_snippet_blob.html.haml +++ b/app/views/search/results/_snippet_blob.html.haml @@ -39,7 +39,7 @@ .blob-content - snippet_chunks.each do |chunk| - unless chunk[:data].empty? - = highlight(snippet.file_name, chunk[:data], plain: snippet.blob.no_highlighting?) + = highlight(snippet.file_name, chunk[:data]) - else .file-content.code .nothing-here-block Empty file |