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 |
# 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
#call ⇒ Object
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_users ⇒ Array<Thredded.user_class>
Returns 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 |