Class: Gitlab::Highlight
- Inherits:
-
Object
- Object
- Gitlab::Highlight
- Defined in:
- lib/gitlab/highlight.rb
Instance Attribute Summary collapse
-
#blob_name ⇒ Object
readonly
Returns the value of attribute blob_name.
Class Method Summary collapse
- .file_size_limit ⇒ Object
- .highlight(blob_name, blob_content, language: nil, plain: false, context: {}, used_on: :blob) ⇒ Object
- .too_large?(size) ⇒ Boolean
Instance Method Summary collapse
- #highlight(text, continue: false, plain: false, context: {}, used_on: :blob) ⇒ Object
-
#initialize(blob_name, blob_content, language: nil) ⇒ Highlight
constructor
A new instance of Highlight.
- #lexer ⇒ Object
Constructor Details
#initialize(blob_name, blob_content, language: nil) ⇒ Highlight
Returns a new instance of Highlight.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gitlab/highlight.rb', line 16 def initialize(blob_name, blob_content, language: nil) @formatter = Rouge::Formatters::HTMLGitlab @language = language @blob_name = blob_name @blob_content = blob_content @gitlab_highlight_usage_counter = Gitlab::Metrics.counter( :gitlab_highlight_usage, 'The number of times Gitlab::Highlight is used' ) end |
Instance Attribute Details
#blob_name ⇒ Object (readonly)
Returns the value of attribute blob_name.
14 15 16 |
# File 'lib/gitlab/highlight.rb', line 14 def blob_name @blob_name end |
Class Method Details
.file_size_limit ⇒ Object
45 46 47 |
# File 'lib/gitlab/highlight.rb', line 45 def self.file_size_limit Gitlab.config.extra['maximum_text_highlight_size_kilobytes'].kilobytes end |
.highlight(blob_name, blob_content, language: nil, plain: false, context: {}, used_on: :blob) ⇒ Object
5 6 7 8 |
# File 'lib/gitlab/highlight.rb', line 5 def self.highlight(blob_name, blob_content, language: nil, plain: false, context: {}, used_on: :blob) new(blob_name, blob_content, language: language) .highlight(blob_content, continue: false, plain: plain, context: context, used_on: used_on) end |
.too_large?(size) ⇒ Boolean
10 11 12 |
# File 'lib/gitlab/highlight.rb', line 10 def self.too_large?(size) size.to_i > self.file_size_limit end |
Instance Method Details
#highlight(text, continue: false, plain: false, context: {}, used_on: :blob) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/gitlab/highlight.rb', line 27 def highlight(text, continue: false, plain: false, context: {}, used_on: :blob) @context = context plain ||= self.class.too_large?(text.length) highlighted_text = highlight_text(text, continue: continue, plain: plain, used_on: used_on) highlighted_text = link_dependencies(text, highlighted_text, used_on: used_on) if blob_name highlighted_text end |