Class: Banzai::Filter::CommitRangeReferenceFilter

Inherits:
AbstractReferenceFilter show all
Defined in:
lib/banzai/filter/commit_range_reference_filter.rb

Overview

HTML filter that replaces commit range references with links.

This filter supports cross-project references.

Constant Summary

Constants inherited from AbstractReferenceFilter

AbstractReferenceFilter::REFERENCE_PLACEHOLDER, AbstractReferenceFilter::REFERENCE_PLACEHOLDER_PATTERN

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractReferenceFilter

#call, #current_parent_path, #current_project_namespace_path, #data_attributes_for, #find_for_paths, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, #identifier, identifier, #object_class, #object_link_filter, #object_link_text, #object_link_text_extras, object_name, #object_sym, object_sym, #parent_per_reference, parse_symbol, #record_identifier, #records_per_parent, #references_in, #references_per_parent, #relation_for_paths, symbol_from_match, #url_for_object_cached, #wrap_link

Methods included from CrossProjectReference

#parent_from_ref

Methods inherited from ReferenceFilter

call, #call_and_update_nodes, #data_attribute, #each_node, #element_node?, #group, #ignore_ancestor_query, #nodes, #project, #reference_class, #replace_link_node_with_href, #replace_link_node_with_text, #replace_text_when_pattern_matches, #skip_project_check?, #text_node?, #user, #validate, #yield_valid_link

Methods included from OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

#initialize(*args) ⇒ CommitRangeReferenceFilter

Returns a new instance of CommitRangeReferenceFilter.


21
22
23
24
25
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 21

def initialize(*args)
  super

  @commit_map = {}
end

Class Method Details

.object_classObject


11
12
13
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 11

def self.object_class
  CommitRange
end

.references_in(text, pattern = CommitRange.reference_pattern) ⇒ Object


15
16
17
18
19
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 15

def self.references_in(text, pattern = CommitRange.reference_pattern)
  text.gsub(pattern) do |match|
    yield match, $~[:commit_range], $~[:project], $~[:namespace], $~
  end
end

Instance Method Details

#find_object(project, id) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 27

def find_object(project, id)
  return unless project.is_a?(Project)

  range = CommitRange.new(id, project)

  range.valid_commits? ? range : nil
end

41
42
43
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 41

def object_link_title(range, matches)
  nil
end

#url_for_object(range, project) ⇒ Object


35
36
37
38
39
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 35

def url_for_object(range, project)
  h = Gitlab::Routing.url_helpers
  h.project_compare_url(project,
                                  range.to_param.merge(only_path: context[:only_path]))
end