Class: Thredded::HtmlPipeline::AtMentionFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/thredded/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)

Options Hash (context):

  • :users_provider (#call(usernames))

    given usernames, returns a list of users.



10
11
12
13
14
# File 'lib/thredded/html_pipeline/at_mention_filter.rb', line 10

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



16
17
18
19
20
21
22
23
24
25
# File 'lib/thredded/html_pipeline/at_mention_filter.rb', line 16

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



28
29
30
31
32
33
34
# File 'lib/thredded/html_pipeline/at_mention_filter.rb', line 28

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