Class: Thredded::HtmlPipeline::AtMentionFilter
- Inherits:
-
HTML::Pipeline::Filter
- Object
- HTML::Pipeline::Filter
- Thredded::HtmlPipeline::AtMentionFilter
- 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
- #call ⇒ Object
-
#initialize(doc, context = nil, result = nil) ⇒ AtMentionFilter
constructor
A new instance of AtMentionFilter.
-
#mentioned_users ⇒ Array<Thredded.user_class>
Users that were @-mentioned.
Constructor Details
#initialize(doc, context = nil, result = nil) ⇒ AtMentionFilter
Returns a new instance of AtMentionFilter.
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
#call ⇒ Object
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_users ⇒ Array<Thredded.user_class>
Returns 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 |