From 39ae9a59a59615092fbef189466f37c34f4a7fb1 Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Thu, 6 Sep 2018 12:34:25 +0800 Subject: Make Highlight accept language param This replaces the repository param. This allows more flexiblity as sometimes we have highlight content not related to repository. Sometimes we know ahead of time the language of the content. Lastly language determination seems better fit as a logic in the Blob class. `repository` param is only used to determine the language, which seems to be the responsiblity of Blob. --- app/helpers/blob_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/helpers/blob_helper.rb') diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index ff7f1e3a9aa..52cf9d12287 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true module BlobHelper - def highlight(blob_name, blob_content, repository: nil, plain: false) - plain ||= blob_content.length > Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE - highlighted = Gitlab::Highlight.highlight(blob_name, blob_content, plain: plain, repository: repository) + 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 %(
#{highlighted}
) 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/helpers/blob_helper.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/helpers/blob_helper.rb') 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 %(
#{highlighted}
) -- cgit v1.2.1