Class: Gitlab::Diff::Highlight
- Inherits:
-
Object
- Object
- Gitlab::Diff::Highlight
- Defined in:
- lib/gitlab/diff/highlight.rb
Constant Summary collapse
- PREFIX_REGEXP =
/\A(.)/
Instance Attribute Summary collapse
-
#diff_file ⇒ Object
readonly
Returns the value of attribute diff_file.
-
#diff_lines ⇒ Object
readonly
Returns the value of attribute diff_lines.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #highlight ⇒ Object
-
#initialize(diff_lines, repository: nil) ⇒ Highlight
constructor
A new instance of Highlight.
Constructor Details
#initialize(diff_lines, repository: nil) ⇒ Highlight
Returns a new instance of Highlight.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gitlab/diff/highlight.rb', line 12 def initialize(diff_lines, repository: nil) @repository = repository @project = repository&.project if diff_lines.is_a?(Gitlab::Diff::File) @diff_file = diff_lines @diff_lines = @diff_file.diff_lines else @diff_lines = diff_lines end @raw_lines = @diff_lines.map(&:text) end |
Instance Attribute Details
#diff_file ⇒ Object (readonly)
Returns the value of attribute diff_file.
8 9 10 |
# File 'lib/gitlab/diff/highlight.rb', line 8 def diff_file @diff_file end |
#diff_lines ⇒ Object (readonly)
Returns the value of attribute diff_lines.
8 9 10 |
# File 'lib/gitlab/diff/highlight.rb', line 8 def diff_lines @diff_lines end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'lib/gitlab/diff/highlight.rb', line 8 def project @project end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
8 9 10 |
# File 'lib/gitlab/diff/highlight.rb', line 8 def repository @repository end |
Instance Method Details
#highlight ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab/diff/highlight.rb', line 26 def highlight populate_marker_ranges @diff_lines.map do |diff_line| diff_line = diff_line.dup # ignore highlighting for "match" lines next diff_line if diff_line. rich_line = apply_syntax_highlight(diff_line) rich_line = apply_marker_ranges_highlight(diff_line, rich_line) diff_line.rich_text = rich_line diff_line end end |