Generates a self-contained Elixir module that converts units to their base units, with no dependency on Localize at all.
The generated module is intended for targets where compiling Localize is too expensive — Nerves devices and other embedded builds, where the ~200 modules of the full library cost more compile time than the project itself. Localize stays on the developer's machine as the generator; the emitted file is committed and compiles in milliseconds.
The generated module accepts every unit Localize.Unit accepts, so
there is nothing to select and no arguments to give. That covers the
155 units CLDR defines a conversion for, every SI-prefixed form of
them, every power (square-, cubic-, pow4-), and every compound
built with -per- or by juxtaposition — newton-meter,
kilogram-square-meter, newton-meter-second-per-radian,
millitherm-us-per-square-second. The accepted set is unbounded, so it
is not tabulated: identifiers are parsed and reduced to a canonical
base unit at call time.
Parity with Localize.Unit is structural rather than maintained.
Localize's own unit parser is written as a NimbleParsec template, and
mix nimble_parsec.compile expands it into plain Elixir functions with
no runtime dependency. That expansion is inlined into the generated
file, so the emitted module parses identifiers with the same code
Localize does — there is no second grammar to keep in step.
Base units are canonical: resolve/1 returns the same base identifier
Localize.Unit.BaseUnit.base_unit/1 returns, with the same factor.
Arguments
--moduleis the name of the module to generate, for exampleRobot.Units. The default isUnits.--outputis the path to write. The default is derived from the module name underlib/.
Returns
:okafter writing the generated file.
Examples
$ mix localize.unit.gen_conversions
* creating lib/units.ex
155 units, 655 spellings, every prefixed and compound form of them
$ mix localize.unit.gen_conversions --module Robot.Units
* creating lib/robot/units.ex
$ mix localize.unit.gen_conversions --module Robot.Units --output lib/units.ex