Sha256: 28e32c7aca32bab8bfab6ae2a289e7e6b4282c42c033de781e27094b917f7b3e

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Spina
  module ImagesHelper

    # We wrap some Rails logic inside our own helper method
    # because the resolve directive in ActiveStorage's routes
    # doesn't work outside the main app in 5.2.0.rc2
    def variant(image, options)
      if image.attached? && image.variable?
        variant = image.variant(options)
        main_app.rails_blob_representation_path(variant.blob.signed_id, variant.variation.key, variant.blob.filename)
      elsif image.image?
        # Allows SVGs to be displayed as they are not variable. Requires:
        # - https://github.com/Dreamersoul/administrate-field-active_storage/issues/36#issuecomment-608446819 to be applied
        #
        # Additionally, https://github.com/hopsoft/active_storage_svg_sanitizer/
        # should be added if users are able to upload their own SVG content due to:
        # https://github.com/rails/rails/issues/34665#issuecomment-445888009
        main_app.url_for(image)
      else
        "https://placehold.it/100x100.png"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spina-1.2.0 app/helpers/spina/images_helper.rb
spina-1.1.4 app/helpers/spina/images_helper.rb