Class: Banzai::Filter::References::UserReferenceFilter
- Inherits:
-
ReferenceFilter
- Object
- HTML::Pipeline::Filter
- ReferenceFilter
- Banzai::Filter::References::UserReferenceFilter
- 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
- #call ⇒ Object
-
#references_in(text, pattern = object_reference_pattern) ⇒ Object
Public: Find ‘@user` user references in text.
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
Methods included from Concerns::OutputSafety
Methods included from RequestStoreReferenceCache
#cached_call, #get_or_set_cache
Methods included from Concerns::PipelineTimingCheck
Constructor Details
This class inherits a constructor from Banzai::Filter::References::ReferenceFilter
Instance Method Details
#call ⇒ Object
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 |