Class: Decidim::ContentParsers::ProposalParser
- Inherits:
-
BaseParser
- Object
- BaseParser
- Decidim::ContentParsers::ProposalParser
- Defined in:
- lib/decidim/content_parsers/proposal_parser.rb
Overview
A parser that searches mentions of Proposals in content.
This parser accepts two ways for linking Proposals.
-
Using a standard url starting with http or https.
-
With a word starting with ‘~` and digits afterwards will be considered a possible mentioned proposal.
For example ‘~1234`, but no `~ 1234`.
Also fills a ‘Metadata#linked_proposals` attribute.
Defined Under Namespace
Classes: Metadata
Constant Summary collapse
- URL_REGEX_PART1 =
Matches a URL
'(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|'- URL_REGEX_PART2 =
'\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))'- URL_REGEX =
/#{URL_REGEX_PART1}#{URL_REGEX_PART2}/i- ID_REGEX =
Matches a mentioned Proposal ID (~(d)+ expression)
/~(\d+)/
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(content, context) ⇒ ProposalParser
constructor
A new instance of ProposalParser.
-
#rewrite ⇒ String
Replaces found mentions matching an existing Proposal with a global id for that Proposal.
Constructor Details
#initialize(content, context) ⇒ ProposalParser
Returns a new instance of ProposalParser.
29 30 31 32 |
# File 'lib/decidim/content_parsers/proposal_parser.rb', line 29 def initialize(content, context) super = Metadata.new([]) end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
45 46 47 |
# File 'lib/decidim/content_parsers/proposal_parser.rb', line 45 def end |
Instance Method Details
#rewrite ⇒ String
Replaces found mentions matching an existing Proposal with a global id for that Proposal. Other mentions found that doesn’t match an existing Proposal are returned as they are.
39 40 41 42 |
# File 'lib/decidim/content_parsers/proposal_parser.rb', line 39 def rewrite rewrited_content = parse_for_urls(content) parse_for_ids(rewrited_content) end |