Class: Decidim::ContentParsers::ResourceParser

Inherits:
BaseParser
  • Object
show all
Defined in:
decidim-core/lib/decidim/content_parsers/resource_parser.rb

Overview

A parser that searches mentions of Resources in content.

Direct Known Subclasses

MeetingParser, ProposalParser

Constant Summary collapse

URL_REGEX_SCHEME =

Matches a URL

'(?:http(s)?:\/\/)'
URL_REGEX_CONTENT =
'[\w.-]+[\w\-\._~:\/?#\[\]@!\$&\'\(\)\*\+,;=.]+'
URL_REGEX_END_CHAR =
'[\d]'
ID_REGEX =

Matches a mentioned resource ID (~(d)+ expression)

/~(\d+)/

Constants inherited from BaseParser

BaseParser::Metadata

Instance Attribute Summary

Attributes inherited from BaseParser

#content, #context

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize, #metadata

Methods included from Decidim::ContentProcessor::Common

#html_content?, #html_fragment

Constructor Details

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

Instance Method Details

#rewriteString

Replaces found mentions matching an existing Resource with a global id for that Resource. Other mentions found that does not match an existing Resource are returned as they are.

Returns:

  • (String)

    the content with the valid mentions replaced by a global id.



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

def rewrite
  rewrited_content = parse_for_urls(content)
  parse_for_ids(rewrited_content)
end