Shared helpers for Brix generator mix tasks.
Summary
Functions
Finds a template by name. Normalizes hyphens to underscores.
Returns {:ok, template} or :error.
Finds the latest version directory in a page dir, by timestamp.
Returns {version_name, version_dir} or nil.
Scans a directory for {NN}-* files/dirs and returns the next position number.
Returns 1 if the directory is empty or doesn't exist.
Normalizes a slug: strips leading /, lowercases, validates characters,
then prepends /.
Zero-pads a number to 2 digits.
Resolves the page directory for a given slug.
Slug / maps to index/, others strip leading /.
Parses --content-dir from args, defaulting to priv/content.
Returns {content_dir, parsed_opts, remaining_args}.
Resolves which version to use: explicit --version option, or latest.
Returns {version_name, version_dir} or exits with error.
Generates placeholder field values from a template definition.
Required strings get "TODO", optional get "", booleans get false, etc.
Skips :sections type fields (those become .children/ directories).
Returns the field names in a template that have type :sections.
Converts a template name to a kebab-case filename segment.
"reviews_section" → "reviews-section"
Returns a map of template name → %SectionTemplate{}.
Titleizes a slug segment: "my-page" → "My Page".
Generates YAML from an ordered list of {key, value} pairs.
Handles strings, numbers, booleans, nil, empty maps, and
one level of nested maps (for fields: blocks).
Runs Brix.Validator.validate/1, prints issues, returns :ok or :error.
Functions
Finds a template by name. Normalizes hyphens to underscores.
Returns {:ok, template} or :error.
Finds the latest version directory in a page dir, by timestamp.
Returns {version_name, version_dir} or nil.
Scans a directory for {NN}-* files/dirs and returns the next position number.
Returns 1 if the directory is empty or doesn't exist.
Normalizes a slug: strips leading /, lowercases, validates characters,
then prepends /.
Zero-pads a number to 2 digits.
Resolves the page directory for a given slug.
Slug / maps to index/, others strip leading /.
Parses --content-dir from args, defaulting to priv/content.
Returns {content_dir, parsed_opts, remaining_args}.
extra_switches are merged with the base [content_dir: :string].
Resolves which version to use: explicit --version option, or latest.
Returns {version_name, version_dir} or exits with error.
Generates placeholder field values from a template definition.
Required strings get "TODO", optional get "", booleans get false, etc.
Skips :sections type fields (those become .children/ directories).
Returns the field names in a template that have type :sections.
Converts a template name to a kebab-case filename segment.
"reviews_section" → "reviews-section"
Returns a map of template name → %SectionTemplate{}.
Titleizes a slug segment: "my-page" → "My Page".
Generates YAML from an ordered list of {key, value} pairs.
Handles strings, numbers, booleans, nil, empty maps, and
one level of nested maps (for fields: blocks).
Runs Brix.Validator.validate/1, prints issues, returns :ok or :error.