Class: HTML::Pipeline::AtMentionFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/html/pipeline/at_mention_filter.rb

Constant Summary collapse

DEFAULT_IGNORED_ANCESTOR_TAGS =
%w(pre code tt a style).freeze

Instance Method Summary collapse

Constructor Details

#initialize(doc, context = nil, result = nil) ⇒ AtMentionFilter

Returns a new instance of AtMentionFilter.

Parameters:

  • context (Hash) (defaults to: nil)


9
10
11
12
13
# File 'lib/html/pipeline/at_mention_filter.rb', line 9

def initialize(doc, context = nil, result = nil)
  super doc, context, result
  @users_provider = context[:users_provider]
  @view_context = context[:view_context]
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/html/pipeline/at_mention_filter.rb', line 15

def call
  return doc unless @users_provider
  process_text_nodes! do |node|
    content = node.to_html
    next unless content.include?('@')
    highlight! content
    node.replace content
  end
  doc
end

#mentioned_usersArray<Thredded.user_class>

Returns users that were @-mentioned.

Returns:

  • (Array<Thredded.user_class>)

    users that were @-mentioned



27
28
29
30
31
32
33
# File 'lib/html/pipeline/at_mention_filter.rb', line 27

def mentioned_users
  return [] unless @users_provider
  names = []
  process_text_nodes! { |node| names.concat mentioned_names(node.to_html) }
  names.uniq!
  @users_provider.call(names)
end