Class: Decidim::ContentRenderers::BlobRenderer

Inherits:
BaseRenderer
  • Object
show all
Defined in:
lib/decidim/content_renderers/blob_renderer.rb

Overview

A renderer that searches Global IDs representing blobs in content and replaces it with a URL to these blobs.

e.g. gid://<APP_NAME>/ActiveStorage::Blob/1

OR for representations

e.g. gid://<APP_NAME>/ActiveStorage::Blob/1/<encoded variant transformations>

The ‘<encoded variant transformations>` part of the URL is a Base64 encoded string that contains an unencrypted JSON-encoded value about the blob transformations. This way the specific representations can be stored in the database without having these values expiring.

Constant Summary collapse

GLOBAL_ID_REGEX =

Matches a global id representing a Decidim::User

%r{(gid://[\w-]+/ActiveStorage::Blob/\d+)(/([\w=-]+))?}

Instance Attribute Summary

Attributes inherited from BaseRenderer

#content

Instance Method Summary collapse

Methods inherited from BaseRenderer

#initialize

Methods included from Decidim::ContentProcessor::Common

#html_content?, #html_fragment

Constructor Details

This class inherits a constructor from Decidim::ContentRenderers::BaseRenderer

Instance Method Details

#render(_options = nil) ⇒ String

Replaces found Global IDs matching an existing blob with a URL to that blob. The Global IDs representing an invalid ActiveStorage::Blob are replaced with an empty string.

Returns:

  • (String)

    the content ready to display (contains HTML)



29
30
31
# File 'lib/decidim/content_renderers/blob_renderer.rb', line 29

def render(_options = nil)
  replace_pattern(content, GLOBAL_ID_REGEX)
end