DevJoy.Scene.Asset (DevJoy v2.0.0)

View Source

Provides a way to work with assets, such as images, sounds and other files. It also specifies how the asset should be used in the scene, such as displaying an image as a background or playing a sound repeatedly. You can also choose to store the asset content in the structure or retrieve it at runtime, depending on your use case.

Usage

The asset always requires its type and path. You can also optionally specify additional data and content.

defmodule MyApp.SceneName do
  use DevJoy.Scene

  part :asset do
    asset :background, "/path/to/background.jpg", aspect_ratio: "1:1"

    asset :slide, "/path/to/slide.svg", [] do
      "…"
    end
  end
end

Summary

Field types

The type representing the assets's content.

The type representing the additional data for the asset.

The type representing the assets's path.

The type representing the assets's type.

Main

The asset structure contains the following keys

Returns absolute path for an asset inside a priv directory for the specified project.

t()

The type representing the asset structure.

Field types

content()

@type content() :: binary()

The type representing the assets's content.

data()

@type data() :: Keyword.t()

The type representing the additional data for the asset.

path()

@type path() :: String.t()

The type representing the assets's path.

type()

@type type() :: atom()

The type representing the assets's type.

Main

%DevJoy.Scene.Asset{}

(struct)

The asset structure contains the following keys:

  • content - the binary content of the asset, or nil if the content is not stored in the struct
  • data - a keyword list of additional data for the asset
  • path - the file path of the asset, or nil if the path is not stored in the struct
  • type - the type of the asset, represented as an atom

priv_path(asset, otp_app)

@spec priv_path(t(), otp_app :: atom()) :: String.t()

Returns absolute path for an asset inside a priv directory for the specified project.

static_path(asset, base_path_or_endpoint_or_uri \\ nil)

@spec static_path(t(), base_path | endpoint | uri | nil) :: String.t()
when base_path: String.t(), endpoint: module(), uri: URI.t()

Returns a static path to the asset.

t()

@type t() :: %DevJoy.Scene.Asset{
  content: content() | nil,
  data: data(),
  path: path() | nil,
  type: type()
}

The type representing the asset structure.