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.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractReferenceFilter

#call, data_reference, #find_object_cached, #object_class, object_class_title, #object_class_title, #object_link_filter, #object_link_text, #object_link_text_extras, object_name, #object_sym, object_sym, #project_from_ref_cache, #references_in, #url_for_object_cached

Methods included from CrossProjectReference

#project_from_ref

Methods inherited from ReferenceFilter

#data_attribute, #each_node, #element_node?, #escape_once, #ignore_ancestor_query, #project, #reference_class, #replace_link_node_with_href, #replace_link_node_with_text, #replace_text_when_pattern_matches, #text_node?, user_can_reference?, user_can_see_reference?, #validate, #yield_valid_link

Constructor Details

#initialize(*args) ⇒ CommitRangeReferenceFilter


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

def initialize(*args)
  super

  @commit_map = {}
end

Class Method Details

.find_object(project, id) ⇒ Object


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

def self.find_object(project, id)
  range = CommitRange.new(id, project)

  range.valid_commits? ? range : nil
end

.object_classObject


7
8
9
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 7

def self.object_class
  CommitRange
end

.referenced_by(node) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 17

def self.referenced_by(node)
  project = Project.find(node.attr("data-project")) rescue nil
  return unless project

  id = node.attr("data-commit-range")
  range = find_object(project, id)

  return unless range

  { commit_range: range }
end

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


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

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

Instance Method Details

#find_object(*args) ⇒ Object


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

def find_object(*args)
  self.class.find_object(*args)
end

51
52
53
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 51

def object_link_title(range)
  range.reference_title
end

#url_for_object(range, project) ⇒ Object


45
46
47
48
49
# File 'lib/banzai/filter/commit_range_reference_filter.rb', line 45

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