diff options
author | Mark Chao <mchao@gitlab.com> | 2019-01-23 11:50:19 +0300 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2019-03-06 10:50:55 +0300 |
commit | 90527b9f842d53595fb14a97a8f8ad19d9dc505a (patch) | |
tree | fed26f765da312e42b19e720b94dc3eab7c423b2 /app/presenters | |
parent | 154720cadc05d79fd5a89bfec18b9385964447ec (diff) |
Add full option for blob diff action
Returns all diff lines for frontend if full is true.
Turn UnfoldForm into presenter, and move controller logic to presenter.
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/blobs/unfold_presenter.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/presenters/blobs/unfold_presenter.rb b/app/presenters/blobs/unfold_presenter.rb new file mode 100644 index 00000000000..908b2f97f89 --- /dev/null +++ b/app/presenters/blobs/unfold_presenter.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'gt_one_coercion' + +module Blobs + class UnfoldPresenter < BlobPresenter + include Virtus.model + include Gitlab::Utils::StrongMemoize + + attribute :full, Boolean, default: false + attribute :since, GtOneCoercion + attribute :to, GtOneCoercion + attribute :bottom, Boolean + attribute :unfold, Boolean, default: true + attribute :offset, Integer + attribute :indent, Integer, default: 0 + + def initialize(blob, params) + @subject = blob + @all_lines = highlight.lines + super(params) + + if full? + self.attributes = { since: 1, to: @all_lines.size, bottom: false, unfold: false, offset: 0, indent: 0 } + end + end + + def lines + strong_memoize(:lines) do + lines = @all_lines + lines = lines[since - 1..to - 1] unless full? + lines.map(&:html_safe) + end + end + + def match_line_text + return '' if bottom? + + lines_length = lines.length - 1 + line = [since, lines_length].join(',') + "@@ -#{line}+#{line} @@" + end + end +end |