Class: Decidim::DecidimAwesome::ContentParsers::EditorImagesParser

Inherits:
ContentParsers::BaseParser
  • Object
show all
Defined in:
lib/decidim/decidim_awesome/content_parsers/editor_images_parser.rb

Overview

A parser that searches for editor images from CarrierWave in html contents and replaces them with migrated images to ActiveStorage

See Also:

  • Examples of how to use a content parser

Instance Method Summary collapse

Instance Method Details

#editor_imagesObject



19
20
21
22
23
# File 'lib/decidim/decidim_awesome/content_parsers/editor_images_parser.rb', line 19

def editor_images
  @editor_images ||= parsed_content.search(:img).index_with do |image|
    context[:routes_mappings].find { |mapping| image.attr(:src).end_with?(mapping[:origin_path]) }
  end.compact
end

#rewriteString

Returns the content with the CarrierWave images replaced.

Returns:

  • (String)

    the content with the CarrierWave images replaced.



12
13
14
15
16
17
# File 'lib/decidim/decidim_awesome/content_parsers/editor_images_parser.rb', line 12

def rewrite
  return content if editor_images.blank?

  replace_editor_images
  parsed_content.to_html
end