Class: Decidim::ContentParsers::TagParser

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

Overview

A parser that searches specific tags in the content. This is an abstract class that provides some helper methods for parsing the content and the implementation has to be defined by all the classes that inherit from this class.

Direct Known Subclasses

HashtagParser, UserParser

Constant Summary

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 tags name with new or existing tags models global ids.

The actual tags depend on the context, these can be hashtags, user mentions, user group mentions, etc.

Returns:

  • (String)

    the content with the tags replaced by global ids



18
19
20
21
22
23
24
25
26
27
# File 'decidim-core/lib/decidim/content_parsers/tag_parser.rb', line 18

def rewrite
  if html_content?
    html_fragment.search("span[data-type='#{tag_data_type}']").each do |el|
      el.replace replace_tags(element_tag(el))
    end
    html_fragment.to_s
  else
    replace_tags(content)
  end
end