Class: Banzai::Filter::References::UserReferenceFilter

Inherits:
ReferenceFilter
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/banzai/filter/references/user_reference_filter.rb

Overview

HTML filter that replaces user or group references with links.

A special ‘@all` reference is also supported.

Constant Summary

Constants inherited from ReferenceFilter

ReferenceFilter::REFERENCE_TYPE_ATTRIBUTE, ReferenceFilter::REFERENCE_TYPE_DATA_ATTRIBUTE_NAME

Constants included from Concerns::TextReplacer

Concerns::TextReplacer::REFERENCE_PLACEHOLDER, Concerns::TextReplacer::REFERENCE_PLACEHOLDER_PATTERN

Constants included from Concerns::PipelineTimingCheck

Concerns::PipelineTimingCheck::MAX_PIPELINE_SECONDS

Instance Method Summary collapse

Methods inherited from ReferenceFilter

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

Methods included from Concerns::TextReplacer

#replace_references_in_text_with_html

Methods included from Concerns::HtmlWriter

#write_opening_tag

Methods included from Concerns::OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Methods included from Concerns::PipelineTimingCheck

#exceeded_pipeline_max?

Constructor Details

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

Instance Method Details

#callObject



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

def call
  return doc if project.nil? && group.nil? && !skip_project_check?

  super
end

#references_in(text, pattern = object_reference_pattern) ⇒ Object

Public: Find ‘@user` user references in text

references_in(text) do |match_text, username|
  "<a href=...>@#{user}</a>"
end

text - String text to search.

Yields the String match text, and the String user name.

Returns a HTML String with replacements made, or nil if no replacements were made.

See ReferenceFilter#references_in for a detailed discussion.



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

def references_in(text, pattern = object_reference_pattern)
  replace_references_in_text_with_html(Gitlab::Utils::Gsub.gsub_with_limit(text, pattern,
    limit: Banzai::Filter::FILTER_ITEM_LIMIT)) do |match_data|
    yield match_data[0], match_data[:user]
  end
end