Class: Banzai::Filter::References::SnippetReferenceFilter

Inherits:
AbstractReferenceFilter show all
Defined in:
lib/banzai/filter/references/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.

Constant Summary

Constants inherited from AbstractReferenceFilter

AbstractReferenceFilter::REFERENCE_PLACEHOLDER, AbstractReferenceFilter::REFERENCE_PLACEHOLDER_PATTERN

Instance Method Summary collapse

Methods inherited from AbstractReferenceFilter

#call, #data_attributes_for, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, #identifier, #initialize, #object_link_filter, #object_link_text, #object_link_text_extras, #object_link_title, #parent, #parent_type, #parse_symbol, #record_identifier, #references_in, #symbol_from_match, #url_for_object_cached, #wrap_link

Methods included from CrossProjectReference

#parent_from_ref

Methods inherited from ReferenceFilter

call, #call, #call_and_update_nodes, #each_node, #group, #initialize, #nodes, #object_class, #project, #references_in, #requires_unescaping?

Methods included from OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

This class inherits a constructor from Banzai::Filter::References::AbstractReferenceFilter

Instance Method Details

#find_object(project, id) ⇒ Object


20
21
22
# File 'lib/banzai/filter/references/snippet_reference_filter.rb', line 20

def find_object(project, id)
  reference_cache.records_per_parent[project][id]
end

#parent_records(project, ids) ⇒ Object


14
15
16
17
18
# File 'lib/banzai/filter/references/snippet_reference_filter.rb', line 14

def parent_records(project, ids)
  return unless project.is_a?(Project)

  project.snippets.where(id: ids.to_a)
end

#url_for_object(snippet, project) ⇒ Object


24
25
26
27
28
# File 'lib/banzai/filter/references/snippet_reference_filter.rb', line 24

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