DemoDirector.Demos (DemoDirector v0.1.1)

Copy Markdown View Source

Discovers and parses metadata from saved demo scripts.

Demos are .exs files in priv/demos/ (host-app demos) or dev/priv/demos/ (this package's own demos). Each file's leading comment block is parsed for two pieces of metadata:

  • the first # Demo: … comment becomes the demo's title
  • an optional # @start_at "/path" comment declares which route the demo expects the user to be on before it runs

Anything past the leading comment block is the script body that emits JS via IO.puts.

Summary

Functions

Loads a single demo by name, returning {:ok, demo} or :error.

Lists every saved demo discoverable from the current working directory, sorted by name.

Loads a demo's emitted JS by evaluating its .exs file with stdout captured. Returns the JS as a string.

Extracts {title, start_at} from the leading comment block of a demo script's contents. Returns {nil, nil} if neither is present. Public for testability.

Types

t()

@type t() :: %DemoDirector.Demos{
  name: String.t(),
  path: String.t(),
  start_at: String.t() | nil,
  title: String.t()
}

Functions

fetch(name)

@spec fetch(String.t()) :: {:ok, t()} | :error

Loads a single demo by name, returning {:ok, demo} or :error.

list()

@spec list() :: [t()]

Lists every saved demo discoverable from the current working directory, sorted by name.

load_js(demos)

@spec load_js(t()) :: String.t()

Loads a demo's emitted JS by evaluating its .exs file with stdout captured. Returns the JS as a string.

parse_metadata(contents)

@spec parse_metadata(String.t()) :: {String.t() | nil, String.t() | nil}

Extracts {title, start_at} from the leading comment block of a demo script's contents. Returns {nil, nil} if neither is present. Public for testability.