Sha256: 2c61619b957633be71d9143aaeeb8f25c434cf9a0de3161f1f8e5aba8d887806

Contents?: true

Size: 1.3 KB

Versions: 56

Compression:

Stored size: 1.3 KB

Contents

module Scrivito

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

  def binary_obj_url(obj, binary, image_options = {})
    binary = if image_options.has_key?(:transform)
      apply_custom_transformation(binary, image_options[:transform])
    else
      apply_default_transformation(binary, obj)
    end
    binary_url(binary)
  end

  def resolved_binary_obj_url(obj, binary)
    apply_default_transformation(binary, obj).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)
    encrypted_params = BinaryParamVerifier.generate(binary)
    scrivito_engine.binary_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, obj)
    if (transformation_definition = Scrivito::Configuration.default_image_transformation) &&
        obj.apply_image_transformation?
      binary.transform(transformation_definition)
    else
      binary
    end
  end
end

end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
scrivito_sdk-1.5.5 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.5.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.4.3 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.4 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.4.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.3 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.3.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.2 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.2.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.1.rc2 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.1.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.0 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.0.rc2 lib/scrivito/binary_routing.rb
scrivito_sdk-1.5.0.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.4.2 lib/scrivito/binary_routing.rb
scrivito_sdk-1.4.1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.4.1.rc1 lib/scrivito/binary_routing.rb
scrivito_sdk-1.4.0 lib/scrivito/binary_routing.rb
scrivito_sdk-1.4.0.rc2 lib/scrivito/binary_routing.rb