Sha256: 98475404a040b8f0c51dc3fddaca7d851edf76698ece58511396c8d15fcacea1

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

module Scrivito

class BinaryRouting < Struct.new(:request, :scrivito_engine)
  def binary_url(binary, redirect_url_or_path)
    binary_url_from_cache(binary) || binary_redirect_url(binary, redirect_url_or_path)
  end

  def transformed_binary_url(binary, redirect_url_or_path, image_options = {})
    binary = if image_options.key?(:transform)
      apply_custom_transformation(binary, image_options[:transform])
    else
      apply_default_transformation(binary)
    end
    binary_url(binary, redirect_url_or_path)
  end

  def resolved_binary_url(binary)
    BinaryRewrite.call(request, apply_default_transformation(binary).url)
  end

  private

  def binary_url_from_cache(binary)
    if url_from_cache = binary.url_from_cache
      BinaryRewrite.call(request, url_from_cache)
    end
  end

  def binary_redirect_url(binary, url_or_path)
    encrypted_params = BinaryParamVerifier.generate(binary)
    scrivito_engine.public_send("binary_#{url_or_path}", encrypted_params: encrypted_params)
  end

  def apply_custom_transformation(binary, transformation_definition)
    if transformation_definition
      binary.transform(transformation_definition)
    else
      binary
    end
  end

  def apply_default_transformation(binary)
    if Scrivito::Configuration.default_image_transformation
      binary.transform(Scrivito::Configuration.default_image_transformation)
    else
      binary
    end
  end
end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
scrivito_sdk-1.18.0 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.18.0.rc1 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.17.0 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.17.0.rc3 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.17.0.rc2 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.17.0.rc1 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.16.0 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.16.0.rc2 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.16.0.rc1 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.15.0 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.15.0.rc2 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.15.0.rc1 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.14.0 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.14.0.rc3 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.14.0.rc2 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.14.0.rc1 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.13.0 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.13.0.rc2 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.13.0.rc1 app/cms/scrivito/binary_routing.rb
scrivito_sdk-1.12.0 app/cms/scrivito/binary_routing.rb