Class: Blobs::UnfoldPresenter

Inherits:
BlobPresenter show all
Includes:
ActiveModel::AttributeAssignment, ActiveModel::Attributes, Gitlab::Utils::StrongMemoize
Defined in:
app/presenters/blobs/unfold_presenter.rb

Instance Attribute Summary

Attributes included from Gitlab::View::Presenter::Base

#subject

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BlobPresenter

#highlight, #web_path, #web_url

Methods included from Gitlab::View::Presenter::Base

#can?, #declarative_policy_delegate, #is_a?, #present, #url_builder, #web_path, #web_url

Methods included from Gitlab::Allowable

#can?

Methods included from Gitlab::Routing

add_helpers, includes_helpers, redirect_legacy_paths, url_helpers

Constructor Details

#initialize(blob, params) ⇒ UnfoldPresenter

Returns a new instance of UnfoldPresenter.


21
22
23
24
25
26
27
28
29
30
# File 'app/presenters/blobs/unfold_presenter.rb', line 21

def initialize(blob, params)
  super(blob)
  self.attributes = params

  # Load all blob data first as we need to ensure they're all loaded first
  # so we can accurately show the rest of the diff when unfolding.
  load_all_blob_data

  handle_full_or_end!
end

Instance Method Details

#diff_linesObject

Returns an array of Gitlab::Diff::Line with match line added


33
34
35
36
37
38
39
40
41
42
43
# File 'app/presenters/blobs/unfold_presenter.rb', line 33

def diff_lines
  diff_lines = lines.map.with_index do |line, index|
    full_line = limited_blob_lines[index].delete("\n")

    Gitlab::Diff::Line.new(full_line, nil, nil, nil, nil, rich_text: line)
  end

  add_match_line(diff_lines)

  diff_lines
end

#linesObject


45
46
47
48
49
# File 'app/presenters/blobs/unfold_presenter.rb', line 45

def lines
  strong_memoize(:lines) do
    limit(highlight(to: to).lines).map(&:html_safe)
  end
end

#match_line_textObject


51
52
53
54
55
56
57
# File 'app/presenters/blobs/unfold_presenter.rb', line 51

def match_line_text
  return '' if bottom?

  lines_length = lines.length - 1
  line = [since, lines_length].join(',')
  "@@ -#{line}+#{line} @@"
end