Class: Decidim::ContentParsers::BlobParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/decidim/content_parsers/blob_parser.rb

Overview

Parses any blob URLs from the content and replaces them with references to those blobs.

Constant Summary collapse

BLOB_REGEX =

Matches all possible URLs pointing to ActiveStorage::Blob objects.

Possible routes: get “/blobs/redirect/:signed_id/*filename” get “/blobs/proxy/:signed_id/*filename” get “/blobs/:signed_id/*filename” get “/representations/redirect/:signed_blob_id/:variation_key/*filename” get “/representations/proxy/:signed_blob_id/:variation_key/*filename” get “/representations/:signed_blob_id/:variation_key/*filename” get “/disk/:encoded_key/*filename”

See: github.com/rails/rails/blob/a7e379896552ce43b822385c03c37f2bd47739d3/activestorage/config/routes.rb#L5-L14

%r{
  # Group 1: Host part
  (?<host_part>
    # Group 2: Domain and subpath part
    #{URI::DEFAULT_PARSER.make_regexp(%w(https http))}
  )?
  /rails/active_storage
  # Group 3: Blob path, representation path or disk service path
  /(?<type_part>blobs/redirect|blobs/proxy|blobs|representations/redirect|representations/proxy|representations|disk)
  # Group 4: Signed ID for blobs or encoded key for disk service
  /(?<key_part>[^/]+)
  # Group 5: Variation part (only for representations)
  (
    # Group 6: Variation key for representations
    /(?<variation_part>[\w.=-]+)
  )?
  # Group 7: Filename
  /([\w.=-]+)
}x

Constants inherited from BaseParser

Decidim::ContentParsers::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

#rewriteObject



41
42
43
# File 'lib/decidim/content_parsers/blob_parser.rb', line 41

def rewrite
  replace_blobs(content)
end