mix locale_slug.gen (LocaleSlug v0.2.0)

Copy Markdown View Source

Reads the YAML tables under priv/ and writes lib/locale_slug/generated_tables.ex.

The generated file is committed. That is what lets yamerl be a dev-only dependency and the shipped package carry no dependencies at all — a consumer compiles plain Elixir. test/generated_tables_test.exs regenerates in a temp dir and fails if the committed file has drifted, so the two cannot silently diverge.

mix locale_slug.gen          # regenerate
mix locale_slug.gen --check  # exit 1 if the committed file is stale

Validation happens here, not at runtime

A bad table should break the build of whoever wrote it, not produce a quietly wrong URL for someone downstream. Rejected:

  • an output containing anything but [a-z0-9] or the separator token — including a literal -, since hardcoding it would defeat separator: "_"
  • a rule list whose last branch carries a condition (no default), or where a default appears anywhere but last
  • word_final conjoined with followed_by — unsatisfiable: if the match ends the word there is no following grapheme to classify
  • an L0 key longer than one grapheme, which would break the engine's guarantee that cross-layer competition is always a length tie
  • a class containing σ but not ς — final sigma is not the canonical base of sigma, and step 1 creates it by lowercasing word-final Σ
  • a key whose lowercase form differs from itself (tables are keyed lowercased)

Summary

Functions

Loads and validates every table under dir, returning %{base:, scripts:, locales:}.

The source that run/1 would write, without writing it.

Functions

load_from(dir)

Loads and validates every table under dir, returning %{base:, scripts:, locales:}.

Public so the validation tests can point it at a temp directory of deliberately broken tables. Every guard in this module is a reason a bad table never reaches a URL, which makes them worth testing directly rather than trusting.

render_current()

The source that run/1 would write, without writing it.

Exists so the drift test can compare against the committed file in-process rather than shelling out to a second mix run.