MobDev.Style (mob_dev v0.7.29)

Copy Markdown View Source

The styles lane (MOB_STYLES.md), minimum-viable slice: token-only style packages. A style package ships priv/mob_style.exs declaring a theme module; activation is config :mob, :styles, [...] plus config :mob, :default_style, :name in mob.exs, and the runtime manifest carries the resolved set so core can apply the default style's theme at boot.

A style may also bundle font files (assets: %{fonts: [...]}, paths relative to the style package root) for its theme's fonts: map; the build ships them exactly like plugin fonts (fonts!/1).

Tokens-only is the doc's smallest tier ("repalette-only styles"); the per-component native-override tier (cascade, _style dispatch — the mob_m3 case) is NOT implemented yet.

Summary

Functions

The activated styles as {style_dir, manifest} pairs. Names that don't resolve to a dep or whose manifest fails to load are skipped (surfaced by validation at build).

Activated style names from mob.exs's config :mob, :styles (Application env fallback when there is no mob.exs, mirroring MobDev.Plugin.activated_names/1). A mob.exs that fails to evaluate raises.

The configured :default_style name (or nil). Same sourcing as activated_names/1.

Absolute paths of the fonts the given styles (default: the activated ones) bundle via assets: %{fonts: [...]}, resolved against each style's package dir. Raises when a manifest is invalid or a declared font file doesn't exist, so the build fails instead of shipping a theme whose fonts fall back to the system face. A style activated/0 couldn't resolve or load contributes nothing here.

Loads a style manifest from style_dir. {:ok, map}, or {:error, reason} when the file is missing/unreadable/not a map (styles REQUIRE a manifest — there is no tier-0 equivalent).

The runtime-manifest entries for the activated styles: [%{name, theme}]. Raises at build when an activated style's manifest is invalid or the configured :default_style isn't among the activated styles — a misconfigured style must fail the BUILD, not silently render baseline.

Validates the four required fields (MOB_STYLES.md "Minimum viable manifest"): :name atom, :mob_version requirement string, :style_spec_version integer, :theme module atom; plus the optional :assets, a map whose only supported key is :fonts (a list of path strings relative to the style package root).

Functions

activated()

@spec activated() :: [{Path.t(), map()}]

The activated styles as {style_dir, manifest} pairs. Names that don't resolve to a dep or whose manifest fails to load are skipped (surfaced by validation at build).

activated_names(project_dir \\ File.cwd!())

@spec activated_names(Path.t()) :: [atom()]

Activated style names from mob.exs's config :mob, :styles (Application env fallback when there is no mob.exs, mirroring MobDev.Plugin.activated_names/1). A mob.exs that fails to evaluate raises.

default_style(project_dir \\ File.cwd!())

@spec default_style(Path.t()) :: atom() | nil

The configured :default_style name (or nil). Same sourcing as activated_names/1.

fonts!(styles \\ activated())

@spec fonts!([{Path.t(), map()}]) :: [Path.t()]

Absolute paths of the fonts the given styles (default: the activated ones) bundle via assets: %{fonts: [...]}, resolved against each style's package dir. Raises when a manifest is invalid or a declared font file doesn't exist, so the build fails instead of shipping a theme whose fonts fall back to the system face. A style activated/0 couldn't resolve or load contributes nothing here.

load(style_dir)

@spec load(Path.t()) :: {:ok, map()} | {:error, String.t()}

Loads a style manifest from style_dir. {:ok, map}, or {:error, reason} when the file is missing/unreadable/not a map (styles REQUIRE a manifest — there is no tier-0 equivalent).

runtime_entries!()

@spec runtime_entries!() :: %{styles: [map()], default_style: atom() | nil}

The runtime-manifest entries for the activated styles: [%{name, theme}]. Raises at build when an activated style's manifest is invalid or the configured :default_style isn't among the activated styles — a misconfigured style must fail the BUILD, not silently render baseline.

validate(manifest)

@spec validate(map()) :: {:ok, map()} | {:error, [String.t()]}

Validates the four required fields (MOB_STYLES.md "Minimum viable manifest"): :name atom, :mob_version requirement string, :style_spec_version integer, :theme module atom; plus the optional :assets, a map whose only supported key is :fonts (a list of path strings relative to the style package root).