A behavior for the different kinds of document types in Magma.
Besides the callback definition, it provides shared fields and logic between all document types. Each document type defines additional fields for its specific tasks and a path scheme that determines where instances of this type are stored.
Note, that in general the content under the YAML frontmatter of a document
is not further interpreted.
Magma.DocumentStruct allows to get the AST of a Markdown document.
Summary
Callbacks
Builds the path of a new document during its creation.
Document type specific logic when loading a document.
Renders the document type specific fields as YAML front matter lines.
The title of the document used in the initial top-level header of a document.
Functions
Saves the changes on a document.
Returns the document type module for the given string.
Returns if the given module is a document type module.
Returns the document type name for the given document.
Types
@type t() :: Magma.Prompt.t() | Magma.PromptResult.t() | Magma.Session.t()
@type type() :: module()
Callbacks
Builds the path of a new document during its creation.
The function will receive a struct created with the respective new function, which should
have initialized all parts required for this path building step.
Document type specific logic when loading a document.
Usually the document type specific fields of the YAML front matter of the document are extracted and interpreted here.
Renders the document type specific fields as YAML front matter lines.
The title of the document used in the initial top-level header of a document.
Functions
Saves the changes on a document.
Returns the document type module for the given string.
Example
iex> Magma.Document.type("Prompt")
Magma.Prompt
iex> Magma.Document.type("Session")
Magma.Session
iex> Magma.Document.type("PromptResult")
Magma.PromptResult
iex> Magma.Document.type("Config.System")
Magma.Config.System
iex> Magma.Document.type("Vault")
nil
iex> Magma.Document.type("NonExisting")
nil
Returns if the given module is a document type module.
Returns the document type name for the given document.
Example
iex> Magma.Document.type_name(Magma.Prompt)
"Prompt"
iex> Magma.Document.type_name(Magma.PromptResult)
"PromptResult"
iex> Magma.Document.type_name(Magma.Session)
"Session"
iex> Magma.Document.type_name(Magma.Vault)
** (RuntimeError) Invalid Magma.Document type: Magma.Vault
iex> Magma.Document.type_name(NonExisting)
** (RuntimeError) Invalid Magma.Document type: NonExisting