View Source Magma.Matter behaviour (Magma v0.2.0)
Behaviour for types of matter that can be subject of a Magma.Concept
and the Magma.Artefact
s generated from these concepts.
This module defines a set of callbacks that each matter type must implement. These callbacks allow for the specification of various properties and behaviours of the matter type, such as the available artefacts, paths for different kinds of documents, texts for different parts of the concept and prompt documents, and more.
Summary
Callbacks
A callback that returns the list of Magma.Artefact
types that are available for this matter type.
A callback that returns the name of the Magma.Concept
document.
A callback that returns the title header text of the Magma.Concept
document.
A callback that allows to specify texts which should be included generally in the "Context knowledge" section of the Magma.Artefact.Prompt
document about this type of matter.
A callback that can be used to define additional sections for the Magma.Concept
document.
A callback that returns a list of Obsidian aliases for the Magma.Concept
document of this type of matter.
A callback that returns a text for the body of the "Description" section in the Magma.Concept
document.
A callback that extracts an instance of this matter type from the matter-specific fields of the metadata during deserialization of a Magma.Concept
document.
A callback that returns the section title for the concept description of a type of matter in the Magma.Artefact.Prompt
.
A callback that can be used to define a general description of some matter which should be included in the Magma.Artefact.Prompt
.
A callback that returns the path segment to be used for different kinds of documents for this type of matter.
A callback that returns the path for Magma.Concept
documents about this type of matter.
A callback that renders the matter-specific fields of this type of matter to YAML frontmatter.
Functions
Extracts an instance of a matter from the matter-specific fields of the metadata of a Magma.Concept
document.
Returns a list of the shared fields of the structs of every type of Magma.Matter
.
Returns the matter type module for the given string.
Checks if the given module
is a Magma.Matter
type module.
Returns the matter type name for the given matter type module.
Types
Callbacks
@callback artefacts() :: [Magma.Artefact.t()]
A callback that returns the list of Magma.Artefact
types that are available for this matter type.
A callback that returns the name of the Magma.Concept
document.
Note that this name must unique across all document names in the vault.
A callback that returns the title header text of the Magma.Concept
document.
@callback context_knowledge(Magma.Concept.t()) :: binary() | nil
A callback that allows to specify texts which should be included generally in the "Context knowledge" section of the Magma.Artefact.Prompt
document about this type of matter.
@callback custom_concept_sections(Magma.Concept.t()) :: binary() | nil
A callback that can be used to define additional sections for the Magma.Concept
document.
A callback that returns a list of Obsidian aliases for the Magma.Concept
document of this type of matter.
A callback that returns a text for the body of the "Description" section in the Magma.Concept
document.
As the description is something written by the user, this should return a comment with a hint of what is expected to be written.
extract_from_metadata(document_name, document_title, document_metadata)
View Source@callback extract_from_metadata( document_name :: binary(), document_title :: binary(), document_metadata :: map() ) :: {:ok, t(), keyword()} | {:error, any()}
A callback that extracts an instance of this matter type from the matter-specific fields of the metadata during deserialization of a Magma.Concept
document.
All YAML frontmatter properties are loaded first into the :custom_metadata
map of a Magma.Document
. This callback implementation should Map.pop/2
the
matter-specific entries from the given document_metadata
and return the created
instance of this matter type and the consumed metadata in an ok tuple.
Counterpart of render_front_matter/1
.
A callback that returns the section title for the concept description of a type of matter in the Magma.Artefact.Prompt
.
A callback that can be used to define a general description of some matter which should be included in the Magma.Artefact.Prompt
.
This is used for example to include the code of module, in the case of Magma.Matter.Module
.
A callback that returns the path segment to be used for different kinds of documents for this type of matter.
This path segment will be incorporated in the path generator functions
of the Magma.Document
types.
A callback that returns the path for Magma.Concept
documents about this type of matter.
This path is relative to the Magma.Vault.concept_path/0
A callback that renders the matter-specific fields of this type of matter to YAML frontmatter.
Counterpart of extract_from_metadata/3
.
Functions
Extracts an instance of a matter from the matter-specific fields of the metadata of a Magma.Concept
document.
This function first extracts the matter type from the magma_matter_type
field
in the YAML frontmatter and then delegates to the extract_from_metadata/3
implementation to process the matter-type specific fields.
Returns a list of the shared fields of the structs of every type of Magma.Matter
.
iex> Magma.Matter.fields()
[:name]
Returns the matter type module for the given string.
Example
iex> Magma.Matter.type("Module")
Magma.Matter.Module
iex> Magma.Matter.type("Project")
Magma.Matter.Project
iex> Magma.Matter.type("Vault")
nil
iex> Magma.Matter.type("NonExisting")
nil
Checks if the given module
is a Magma.Matter
type module.
Returns the matter type name for the given matter type module.
Example
iex> Magma.Matter.type_name(Magma.Matter.Module)
"Module"
iex> Magma.Matter.type_name(Magma.Matter.Text)
"Text"
iex> Magma.Matter.type_name(Magma.Matter.Text.Section)
"Text.Section"
iex> Magma.Matter.type_name(Magma.Vault)
** (RuntimeError) Invalid Magma.Matter type: Magma.Vault
iex> Magma.Matter.type_name(NonExisting)
** (RuntimeError) Invalid Magma.Matter type: NonExisting