Mix.Generator

Conveniences for working with paths and generating content.

All of those functions are verbose, in the sense they log the action to be performed via Mix.shell.

Source

Summary

create_directory(path)

Creates a directory if one does not exist yet

create_file(path, contents)

Creates a file with the given contents. If the file already exists, asks for user confirmation

embed_template(name, contents)

Embed a template given by contents into the current module

embed_text(name, contents)

Embeds a text given by contents into the current module

from_file(path)

Reads the content from a file relative to the current file and not relative to the cwd. Useful when used with embed macros:

Functions

create_directory(path)

Creates a directory if one does not exist yet.

Source
create_file(path, contents)

Creates a file with the given contents. If the file already exists, asks for user confirmation.

Source

Macros

embed_template(name, contents)

Embed a template given by contents into the current module.

It will define a private function with the name followed by _template that expects assigns as arguments.

This function must be invoked passing a keyword list. Each key in the keyword list can be accessed in the template using the @ macro.

For more information, check EEx.SmartEngine.

Source
embed_text(name, contents)

Embeds a text given by contents into the current module.

It will define a private function with the name followed by _text that expects no argument.

Source
from_file(path)

Reads the content from a file relative to the current file and not relative to the cwd. Useful when used with embed macros:

embed_template :lib, from_file("../templates/lib.eex")
Source