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

Inherits:
ReferenceFilter
  • Object
show all
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.

Instance Method Summary collapse

Methods inherited from ReferenceFilter

call, #call_and_update_nodes, #each_node, #group, #initialize, #nodes, #object_class, #project, #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::ReferenceFilter

Instance Method Details

#callObject


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

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, username|
  "<a href=...>@#{user}</a>"
end

text - String text to search.

Yields the String match, and the String user name.

Returns a String replaced with the return of the block.


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

def references_in(text, pattern = object_reference_pattern)
  text.gsub(pattern) do |match|
    yield match, $~[:user]
  end
end