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
15
# 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]
  @users_provider_scope = context[:users_provider_scope]
  @view_context = context[:view_context]
end

Instance Method Details

#callObject



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

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



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

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, @users_provider_scope)
end