MontyCad.Gen (ExMontyCad v0.2.0)

Copy Markdown View Source

The shared half of the code generators: what a plugin is called, where it goes, and that what is written is formatted.

A generator that writes unformatted code teaches the wrong thing on its first line, so every source here goes through the formatter before it is written. A generator that writes into the wrong namespace is worse: the module would be in this package's namespace while the plugin belongs to the application that asked for it, so the namespace comes from the project's own :app.

Summary

Functions

Where the module's source goes.

One source as the formatter leaves it.

The module a plugin name becomes, in the host application's namespace.

The module a plugin name becomes, or the reason it is not a name.

The application this generation is for, as a module prefix.

Where the module's test goes.

Writes the files a generator made, and answers the paths it wrote.

Functions

file_path(module)

@spec file_path(module()) :: Path.t()

Where the module's source goes.

format(source)

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

One source as the formatter leaves it.

module_name(name)

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

The module a plugin name becomes, in the host application's namespace.

follow_chamfers in an application called my_agent is MyAgent.Plugins.FollowChamfers.

module_name!(name)

@spec module_name!(String.t()) :: module()

The module a plugin name becomes, or the reason it is not a name.

namespace()

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

The application this generation is for, as a module prefix.

test_path(module)

@spec test_path(module()) :: Path.t()

Where the module's test goes.

write!(files)

@spec write!([{Path.t(), String.t()}]) :: [Path.t()]

Writes the files a generator made, and answers the paths it wrote.

An existing file is refused rather than overwritten: a generator run a second time by mistake would otherwise take the decisions the first run's owner has since written into it.