Francis.Static (Francis v0.2.0)

View Source

Utilities for working with static assets.

This module provides functions to resolve static paths and URLs, including support for digested assets generated by mix francis.digest.

Summary

Functions

all(manifest_path \\ "priv/static/cache_manifest.json")

Returns all assets from the manifest.

Examples

iex> Francis.Static.all()
%{
  "app.css" => %{
    "digest" => "a1b2c3d4",
    "digested_path" => "app-a1b2c3d4.css",
    "size" => 1024
  }
}

exists?(logical_path, manifest_path \\ "priv/static/cache_manifest.json")

Checks if an asset exists in the manifest.

Examples

iex> Francis.Static.exists?("app.css")
true

iex> Francis.Static.exists?("nonexistent.css")
false

load_manifest(manifest_path \\ "priv/static/cache_manifest.json")

Loads the cache manifest from the given path.

Returns {:ok, manifest} on success, {:error, reason} on failure.

Examples

iex> Francis.Static.load_manifest("priv/static/cache_manifest.json")
{:ok, %{"version" => 1, "files" => %{...}}}

iex> Francis.Static.load_manifest("nonexistent.json")
{:error, :enoent}

static_path(logical_path, base_path \\ "/", manifest_path \\ "priv/static/cache_manifest.json")

Returns the path for the given asset.

If a digest manifest is available and the asset is found in it, returns the digested path. Otherwise, returns the original path.

Examples

iex> Francis.Static.static_path("app.css")
"app-a1b2c3d4.css"