Class: Banzai::Filter::SnippetReferenceFilter

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

Overview

HTML filter that replaces snippet references with links. References to snippets that do not exist are ignored.

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_link_title, object_name, #object_sym, object_sym, #project_from_ref_cache, referenced_by, references_in, #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, referenced_by, #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

Class Method Details

.object_classObject


8
9
10
# File 'lib/banzai/filter/snippet_reference_filter.rb', line 8

def self.object_class
  Snippet
end

Instance Method Details

#find_object(project, id) ⇒ Object


12
13
14
# File 'lib/banzai/filter/snippet_reference_filter.rb', line 12

def find_object(project, id)
  project.snippets.find_by(id: id)
end

#url_for_object(snippet, project) ⇒ Object


16
17
18
19
20
# File 'lib/banzai/filter/snippet_reference_filter.rb', line 16

def url_for_object(snippet, project)
  h = Gitlab::Routing.url_helpers
  h.namespace_project_snippet_url(project.namespace, project, snippet,
                                  only_path: context[:only_path])
end