Class: Decidim::ContentParsers::UserParser

Inherits:
TagParser show all
Defined in:
decidim-core/lib/decidim/content_parsers/user_parser.rb

Overview

A parser that searches user mentions in content.

A word starting with ‘@` will be considered as a possible mention if they only contains letters, numbers or underscores.

Direct Known Subclasses

UserGroupParser

Defined Under Namespace

Classes: Metadata

Constant Summary collapse

MENTION_REGEX =

Matches a nickname if contains letters, numbers or underscores.

/\B@(\w*)\b/

Constants inherited from BaseParser

BaseParser::Metadata

Instance Attribute Summary

Attributes inherited from BaseParser

#content, #context

Instance Method Summary collapse

Methods inherited from TagParser

#rewrite

Methods inherited from BaseParser

#initialize, #rewrite

Methods included from Decidim::ContentProcessor::Common

#html_content?, #html_fragment

Constructor Details

This class inherits a constructor from Decidim::ContentParsers::BaseParser

Instance Method Details

#metadataMetadata

This method is abstract.

Subclass is expected to implement it

Collects and returns metadata. This metadata is accessible at parsing time so it can be acted upon (sending emails to the users) or maybe even stored at the DB for later consultation.

Examples:

Implementation for return a counter of prohibited words found

Metadata = Struct.new(:count)

def 
  Metadata.new(content.scan('foo').size)
end

Returns:

  • (Metadata)

    a Metadata object that holds extra information



22
23
24
# File 'decidim-core/lib/decidim/content_parsers/user_parser.rb', line 22

def 
  Metadata.new(existing_mentionables)
end