Storehouse.Renderer behaviour (Storehouse v0.2.0)

Copy Markdown View Source

What makes a file's variants (Storehouse.Variants), or the URLs of the service that makes them. A renderer does one or both:

A renderer with url/3 gives every variant's URL; one with only render/4 has Storehouse.Variants.Plug's. Either way, only the presets' sizes are ever asked for.

Configured as a module, or {module, options}; the options are given to each callback:

config :storehouse, Storehouse.Variants,
  renderer: {Storehouse.Renderer.Imgproxy, url: "https://images.example.com", ...}

A renderer of the app's own (another service's URLs, URLs of its own shape) implements either callback.

Summary

Callbacks

Renders variant from the original at source to destination, a path with the format's extension. Never larger than the original.

The URL of variant. Its :format is a list when the format is to be chosen from the browser's Accept, by the service.

Callbacks

render(source, destination, t, opts)

(optional)
@callback render(
  source :: Path.t(),
  destination :: Path.t(),
  Storehouse.Variant.t(),
  opts :: keyword()
) ::
  :ok | {:error, term()}

Renders variant from the original at source to destination, a path with the format's extension. Never larger than the original.

url(t, t, opts)

(optional)
@callback url(Storehouse.Variant.t(), Storehouse.File.t(), opts :: keyword()) ::
  String.t()

The URL of variant. Its :format is a list when the format is to be chosen from the browser's Accept, by the service.